How to concatenate of results from a loop

4 Ansichten (letzte 30 Tage)
Sunil Kunjachan
Sunil Kunjachan am 14 Jan. 2017
Kommentiert: Andrei Bobrov am 15 Jan. 2017
The output identifies the elements of X that are smaller than the product of their two indexes.
for example;
X=[1 1;0 4;6 5];
p=[];
[col,row]=size(X);
for c=1:col
for r=1:row
if (r*c)<X(r,c)
p=cat(1,p,[r c]);
else
p=[];
end
end
end
The answer should be 2 1 1 2 3 2 But I'm getting only last one i.e. 3 2. What could be wrong in my code? Please help me
  4 Kommentare
Sunil Kunjachan
Sunil Kunjachan am 15 Jan. 2017
But if you try with X=[0;1;2;3;4;5;6;7;8;9;10],the code will work.
Sunil Kunjachan
Sunil Kunjachan am 15 Jan. 2017
I'm trying to get the for X=[1 1;0 4;6 5]. I know the answer. It will be [2 1;1 2;3 2]. I'm getting only last row in that matrix.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Andrei Bobrov
Andrei Bobrov am 14 Jan. 2017
Bearbeitet: Andrei Bobrov am 15 Jan. 2017
X=[1 1;0 4;6 5];
[r,c] = find((1:size(X,1))'*(1:size(X,2)) > X);
p = [r,c];
  2 Kommentare
Sunil Kunjachan
Sunil Kunjachan am 15 Jan. 2017
Thanks for the reply. But I'm not getting the answer!
Andrei Bobrov
Andrei Bobrov am 15 Jan. 2017
fixed :)

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Creating, Deleting, and Querying Graphics Objects finden Sie in Help Center und File Exchange

Tags

Noch keine Tags eingegeben.

Community Treasure Hunt

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

Start Hunting!

Translated by