Info

この質問は閉じられています。 編集または回答するには再度開いてください。

Im trying to print a randomized vector with 20 columns for each row. How do I get to stop after it reaches the final value of the vector?

1 回表示 (過去 30 日間)
Rafael Perales
Rafael Perales 2016 年 10 月 5 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
for s=1:65
rando=randi([0,9],1,65);
fprintf('%d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d \n', rando)
end

回答 (2 件)

Massimo Zanetti
Massimo Zanetti 2016 年 10 月 5 日
There is no need to write them each time. Use vectorization of fprintf command.
rando=randi([0,9],1,65);
fprintf('%d ',rando);
fprintf('\n');

Matthew Eicholtz
Matthew Eicholtz 2016 年 10 月 5 日
If I understand your code correctly, it appears that you want to create a 65x65 matrix of random integers in the range [0 9] that are printed to the command window. In that case, you don't need the for-loop or fprintf for this.
Try this:
rando = randi([0,9],65);
disp(rando);

この質問は閉じられています。

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by