find specific value from each row from matrix (Index, and number)

21 visualizaciones (últimos 30 días)
Ali Tawfik
Ali Tawfik el 29 de Ag. de 2019
Comentada: Adam Danz el 31 de Ag. de 2019
Hi All,
I am trying to find/obtain each value is lower than specific number from each row from a matrix. However I only obtain values from all the matrix.
Here is the code below:
I need to obtain only in each row if there is a number lower than 4 or not, I need both the index, and the real value
x=[1 2 3 4 5]
for i=1:5
sigma1(i)=x(i)+1;
sigma2(i)=x(i)+2;
sigma3(i)=x(i)+3;
sigmaa(:,i)=[sigma1(i) sigma2(i) sigma3(i)]
min_va=find(sigmaa>4); % I need to obtain only in each row if there is a number lower than 4 or not
[r,c]=find(sigmaa>4)
end
Any help please!
  1 comentario
Adam Danz
Adam Danz el 29 de Ag. de 2019
That's a lot of lines to do a simple thing. Also, your comments state that you want to identify values less than 4 but your code is identifying values greater than 4.
Consider these two lines
x = [1 2 3 4 5]; %row vector
isLowerThan = (x + [1;2;3]) < 4;
The produce a logica matrix "isLowerThan" where each column corresponds to one value in "x" compared added to [1;2;3]. The '1's (true's) show where the results are less than 4.

Iniciar sesión para comentar.

Respuestas (1)

KALYAN ACHARJYA
KALYAN ACHARJYA el 29 de Ag. de 2019
Editada: KALYAN ACHARJYA el 29 de Ag. de 2019
I need to obtain only in each row if there is a number lower than 4 or not, I need both the index, and the real value
X=magic(6);
[r c]=find(X<4);
idx=cell(1,length(r));
for i=1:length(r)
idx{i}={r(i),c(i)};
end
idx
Now read the values from X having idx indices (idx cell array, read individually)
  2 comentarios
Ali Tawfik
Ali Tawfik el 31 de Ag. de 2019
Thanks for your reply,
That's not what I need, I need for example, the values in the first row, which is lower than 4.
I need the numbers that;s in your example should be
1
3
2
and nothing in the last 3 rows.
thanks,
Adam Danz
Adam Danz el 31 de Ag. de 2019
That wasn't clear in your question. These lines below produce that output.
x = magic(6);
x = x.';
x(x<4)

Iniciar sesión para comentar.

Categorías

Más información sobre Matrices and Arrays en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by