From: mat001 on 14 May 2010 04:18 Hii If i have matrix A = rand(1,700) A = reshape(A,10,70) B = 1 Now I want to see each element of matrix A should be less than B i. e 1 so how I should start. Should I need loop. Please guide me. Regards
From: Jan Simon on 14 May 2010 04:42 Dear Priya! > If i have matrix > A = rand(1,700) > A = reshape(A,10,70) > B = 1 > Now I want to see each element of matrix A should be less than B i. e 1 so how I should start. At first, I'd start with creating A with the correct dimensions directly: A = rand(10, 70); "Each" element is called "all" in Matlab, but this command operates on vectors. So one method is: All_A_LE_B = all(all(A < B)) all(A < B) replies a vector, which is TRUE if all elements of the corresponding column of A are lower than B. The outer ALL replies TRUE, if all elements of "all(A < B)" are TRUE. Another method: All_A_LE_B = all(A(:) < B) Now A is reshaped to a column vector at first and the 2nd call to ALL is not needed anymore. This can be faster or slower depending on your Matlab version and number of processors. Good luck, Jan
From: mat001 on 14 May 2010 05:05 "Jan Simon" <matlab.THIS_YEAR(a)nMINUSsimon.de> wrote in message <hsj2cu$9dn$1(a)fred.mathworks.com>... > Dear Priya! > > > If i have matrix > > A = rand(1,700) > > A = reshape(A,10,70) > > B = 1 > > Now I want to see each element of matrix A should be less than B i. e 1 so how I should start. > > At first, I'd start with creating A with the correct dimensions directly: > A = rand(10, 70); > "Each" element is called "all" in Matlab, but this command operates on vectors. > So one method is: > All_A_LE_B = all(all(A < B)) > all(A < B) replies a vector, which is TRUE if all elements of the corresponding column of A are lower than B. The outer ALL replies TRUE, if all elements of "all(A < B)" are TRUE. > > Another method: > All_A_LE_B = all(A(:) < B) > Now A is reshaped to a column vector at first and the 2nd call to ALL is not needed anymore. This can be faster or slower depending on your Matlab version and number of processors. > > Good luck, Jan Thanks
From: ImageAnalyst on 14 May 2010 06:24 Of course for the example you gave, ALL elements of A are less than B because A goes only from 0 to 1. Other than that I can't tell what you want because the grammar is ambiguous. I don't know if you mean I want to see each element of matrix A that is less than B A < B, or maybe A(A<B) or maybe [rows columns] = find(A<B) or, I want to ensure that each element of matrix A is less than B A(A<B) = B or maybe something else.
|
Pages: 1 Prev: output the distance values using knnclassify Next: objects from different classes messaging |