find specific value from each row from matrix (Index, and number)
21 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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
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.
Respuestas (1)
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
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)
Ver también
Categorías
Más información sobre Matrices and Arrays en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!