Replace values in matrix based on array values
6 ビュー (過去 30 日間)
古いコメントを表示
Hey guys,
I got a question and feel really dumb for not figuring it out myself.
So lets say I have a random matrix and I want to set all elements that match a specific value given by an array to zero. How do I do it ?
I know that I can do it for single elements, but I have no idea how to do it for several elements at the same time (to avoid for loops).
Example code:
x1=randi([0,10],[4,4])
y1=[3,4]
x1(x1==y1)=0;
0 件のコメント
回答 (2 件)
Rik
2020 年 6 月 4 日
Nobody is born knowing about ismember and ismembertol. (use the latter if you expect float rounding errors)
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Logical についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!