How to swap cells in matrix with code
古いコメントを表示
I have to change the value of every cell in a matrix which is >5. However I am not sure how. I have to include the 'find' function. I have to change every value greater than 5 to 0, I am not sure how.
D=[8 1 6;3 5 7;4 9 2];
[d1,d2]=find(D>5);
d=[d1,d2];
disp(d)
Doing this gives me
>> PBTask4p3
1 1
3 2
1 3
2 3
5 件のコメント
Ameer Hamza
2020 年 9 月 21 日
"include the 'find' function". Is this a homework problem? What is the expected output?
Allen Antony
2020 年 9 月 21 日
Mohammad Sami
2020 年 9 月 21 日
You should look at logical indexing. For your problem you can use find, however it's not necessary.
Allen Antony
2020 年 9 月 21 日
KSSV
2020 年 9 月 21 日
Read about logical indexing.
A = rand(5) ;
idx = A>0.5 ; % logical indexing
A(idx) = 0 ;
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Matrix Indexing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!