Info
Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.
Is there a way to get MATLAB to write out a certain number more than once without typing them individually
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (1)
James Tursa
am 6 Nov. 2017
Bearbeitet: James Tursa
am 6 Nov. 2017
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 Kommentare
James Tursa
am 6 Nov. 2017
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
am 6 Nov. 2017
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.
Diese Frage ist geschlossen.
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!