フィルターのクリア

Info

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

Is there a way to get MATLAB to write out a certain number more than once without typing them individually

2 ビュー (過去 30 日間)
Waseem Hussain
Waseem Hussain 2017 年 11 月 6 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
Hi Is there a way to get MATLAB to write out 20 lots of 1's 20 lots of 2's etc. without typing them out individually
  2 件のコメント
Rik
Rik 2017 年 11 月 6 日
You mean repmat? Or for-loops? (combine it with sprintf or fprintf)
Waseem Hussain
Waseem Hussain 2017 年 11 月 6 日
Sorry I don't know what you mean by that, could you show us an example of how I would do it

回答 (1 件)

James Tursa
James Tursa 2017 年 11 月 6 日
編集済み: James Tursa 2017 年 11 月 6 日
E.g.,
>> ones(1,20)
ans =
Columns 1 through 18
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Columns 19 through 20
1 1
>> ones(1,20)*2
ans =
Columns 1 through 18
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
Columns 19 through 20
2 2
  3 件のコメント
James Tursa
James Tursa 2017 年 11 月 6 日
E.g.,
W = [ones(1,20);2*ones(1,20)];
or
W = ones(2,20);
W(2,:) = 2;
Or if you want columns of numbers, e.g.
W = [ones(20,1),2*ones(20,1)];
or
W = ones(20,2);
W(:,2) = 2;
Rik
Rik 2017 年 11 月 6 日
It sounds like you would really benefit from a starter course on Matlab. Assigning and concatenating variables is probably in the first lesson of every tutorial.

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by