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
Ameer Hamza 2020년 9월 21일
"include the 'find' function". Is this a homework problem? What is the expected output?
D=[0 1 0;3 5 0;4 0 2]
So basically every number greater than 5 becomes 0. yes this is a homework problem
Mohammad Sami
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
Allen Antony 2020년 9월 21일
I will look at it, but I do kind of need find for the task.
Read about logical indexing.
A = rand(5) ;
idx = A>0.5 ; % logical indexing
A(idx) = 0 ;

댓글을 달려면 로그인하십시오.

 채택된 답변

Ameer Hamza
Ameer Hamza 2020년 9월 21일

0 개 추천

Check this
D = [8 1 6;3 5 7;4 9 2];
idx = find(D > 5);
D(idx) = 0;
Result
>> D
D =
0 1 0
3 5 0
4 0 2

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Matrix Indexing에 대해 자세히 알아보기

질문:

2020년 9월 21일

답변:

2020년 9월 21일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by