How do I only show 1 output instead of all the outputs as a result of the matrix
17 ビュー (過去 30 日間)
古いコメントを表示
I'm working a variation of this code and I don't understand how to supppress the output where I don't get all 6 elements every time I run the code. Basically, I just want to see the solution once and not various times in the command window (I just don't know what to add to do that). I've tried variations with display, fft (although I tried this, I am not familiar with the command), and some other commands that just made my solutions disapear. I'm completely stumped.
num=rand(3,2);
[row1,col1]=size(num);
for a=1:row1
for b=1:col1
disp('You chose an appropriate matrix')
end
end
Any advice, or what video/resouce I shoud look at, is appreciated.
0 件のコメント
採用された回答
Walter Roberson
2021 年 2 月 23 日
num = randi(10,3,2);
[row1,col1]=size(num);
foundit = false;
for a=1:row1
for b=1:col1
if num(a,b) == 7
fprintf('You chose an appropriate matrix at (%d,%d)\n', a, b);
foundit = true;
break
end
end
if foundit; break; end
end
if ~foundit
fprintf('Better luck next time!\n');
end
3 件のコメント
Walter Roberson
2021 年 2 月 23 日
yes the %d is just formatting the output, which I did in order to emphasize that the solution could be found at any point in the matrix
if num(a,b) == 7
is not an assignment, it is a test. It is an arbitrary test as it is not clear what you want to do.
その他の回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!