Info
Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.
Print message about which loop has been entered, after finishing for loop
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
I have 4 if statements in a for loop. I need to know which if statement was entered. Can be just one or all 4. after the for loop finishes I will need to print a message saying which entered without repeats or if none were. each if statement being A B C or D in the print message.
I tried assigning a letter to each if statement and if that was entered then add to an array. then look through the array after the for loop and print a message after going through 4 more if statements. I am over complicating it
ex: A and D were entered. None were entered. etc.
let me know if not clear i am ESL. Doing project for fun.
0 Kommentare
Antworten (1)
KL
am 21 Nov. 2017
set counters and use it with disp
counterA = 0;
counterB = 0;
counterNone = 0;
for k=1:10
%code
if (condition A here)
counterA = counterA+1;
disp(['condition A is true. counterA = ' num2str(counterA)]);
elseif (condition B here)
counterB = counterB+1;
disp(['condition B is true. counterB = ' num2str(counterB]);
else
counterNone = counterNone+1;
disp(['No condition is true. counterNone = ' num2str(counterNone]);
end
end
2 Kommentare
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!