How to find the index of the values which are bigger than zero the following case?
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
M
am 31 Aug. 2022
Beantwortet: Image Analyst
am 31 Aug. 2022
How to find the index of the values which are bigger than zero the following case?
There is a vector M contines three value for example, M = [ 0 0.5 0.7] , Note: there is no negative values
How can I write the following progrom:
the first one if the value in index one bigger than zero ... Then I put a condition
the second one if the value in index two bigger than zero ... Then I put a condition
the third one if the value in index three bigger than zero ... Then I put a condition
0 Kommentare
Akzeptierte Antwort
Image Analyst
am 31 Aug. 2022
Simple:
M = [0, 0.5, 0.7];
% the first one if the value in index one bigger than zero ... Then I put a condition
if M(1) > 0
fprintf('Do something because first element is greater than 0.\n')
end
% the second one if the value in index two bigger than zero ... Then I put a condition
if M(2) > 0
fprintf('Do something because second element is greater than 0\n')
end
% the third one if the value in index three bigger than zero ... Then I put a condition
if M(3) > 0
fprintf('Do something because third element is greater than 0\n')
end
0 Kommentare
Weitere Antworten (1)
Torsten
am 31 Aug. 2022
Bearbeitet: Torsten
am 31 Aug. 2022
M = [ 0 0.5 0.7];
[~,indices] = find(M>0)
1 Kommentar
Walter Roberson
am 31 Aug. 2022
Then go ahead and write that series of if/else statements. You will have 8 branches.
Siehe auch
Kategorien
Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!