Filter löschen
Filter löschen

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

16 Ansichten (letzte 30 Tage)
Ali Tawfik
Ali Tawfik am 29 Aug. 2019
Kommentiert: Adam Danz am 31 Aug. 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 Kommentar
Adam Danz
Adam Danz am 29 Aug. 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.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

KALYAN ACHARJYA
KALYAN ACHARJYA am 29 Aug. 2019
Bearbeitet: KALYAN ACHARJYA am 29 Aug. 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 Kommentare
Ali Tawfik
Ali Tawfik am 31 Aug. 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 am 31 Aug. 2019
That wasn't clear in your question. These lines below produce that output.
x = magic(6);
x = x.';
x(x<4)

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Matrices and Arrays finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by