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

23 vues (au cours des 30 derniers jours)
Ali Tawfik
Ali Tawfik le 29 Août 2019
Commenté : Adam Danz le 31 Août 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 commentaire
Adam Danz
Adam Danz le 29 Août 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.

Connectez-vous pour commenter.

Réponses (1)

KALYAN ACHARJYA
KALYAN ACHARJYA le 29 Août 2019
Modifié(e) : KALYAN ACHARJYA le 29 Août 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 commentaires
Ali Tawfik
Ali Tawfik le 31 Août 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 le 31 Août 2019
That wasn't clear in your question. These lines below produce that output.
x = magic(6);
x = x.';
x(x<4)

Connectez-vous pour commenter.

Catégories

En savoir plus sur Matrices and Arrays dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by