How to concatenate of results from a loop

조회 수: 4 (최근 30일)
Sunil Kunjachan
Sunil Kunjachan 2017년 1월 14일
댓글: Andrei Bobrov 2017년 1월 15일
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
Sunil Kunjachan
Sunil Kunjachan 2017년 1월 15일
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 2017년 1월 15일
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.

댓글을 달려면 로그인하십시오.

답변 (1개)

Andrei Bobrov
Andrei Bobrov 2017년 1월 14일
편집: Andrei Bobrov 2017년 1월 15일
X=[1 1;0 4;6 5];
[r,c] = find((1:size(X,1))'*(1:size(X,2)) > X);
p = [r,c];
  댓글 수: 2
Sunil Kunjachan
Sunil Kunjachan 2017년 1월 15일
Thanks for the reply. But I'm not getting the answer!
Andrei Bobrov
Andrei Bobrov 2017년 1월 15일
fixed :)

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Creating, Deleting, and Querying Graphics Objects에 대해 자세히 알아보기

태그

아직 태그를 입력하지 않았습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by