In an assignment A(I) = B, the number of elements in B and I must be the same error
2 ビュー (過去 30 日間)
古いコメントを表示
Hi, I would like to know how to change the 0's in C that are in the same position where d1 finds values where (d<=d0) with the corresponding d value. d is a 100x1 array and d0 is the mean value. For instance if the first and fourth elements in d are less than d0, then the first and fourth elements in d are stored as the first and fourth elements in C respectively.
C=zeros(100,1);
d1=find(d<=d0);
C(d1)=d;
0 件のコメント
採用された回答
Image Analyst
2015 年 4 月 21 日
Almost right. Try this instead:
C=zeros(100,1);
d1 = find(d<=d0);
C(d1)=d(d1);
その他の回答 (1 件)
Star Strider
2015 年 4 月 21 日
編集済み: Star Strider
2015 年 4 月 21 日
Using ‘logical indexing’ works well here:
C = zeros(100,1);
d = randi(10, 100, 1);
d0 = mean(d);
C(d<=d0) = d(d<=d0);
参考
カテゴリ
Help Center および File Exchange で Matrix Indexing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!