How to concatenate of results from a loop
2 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
回答 (1 件)
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];
参考
カテゴリ
Help Center および File Exchange で Creating and Concatenating Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!