Assigning values to an array using elements of another array after each element goes through a check
古いコメントを表示
Hello,
Let's say that i have an array (e.g zeros(5,5)).
I'd like to use each element my array has, put each element through an if statement check, make some calculations, and assign that new value to another array that has the same dimensions as my initial one.
If anybody has any idea i'd be of great help!
Thanks!:)
採用された回答
その他の回答 (1 件)
I'd like to use each element my array has, put each element through an if statement check
Just be aware that that's normally the kind of thing you try to avoid in MATLAB. For instance, YT's example is much more efficiently implemented as follows for large matrices,
condition = start_matrix>0.5;
end_matrix=start_matrix;
end_matrix(condition)=start_matrix(condition)*666;
2 件のコメント
YT
2017 年 12 月 14 日
I agree to what you said, but I think it's useful for beginners to understand how looping through a matrix works.
カテゴリ
ヘルプ センター および File Exchange で Matrix and Vector Construction についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!