How do I create a (10,10) matrix containing numbers from 1 to 100?
Mostra commenti meno recenti
How do I create a (10,10) matrix containing numbers from 1 to 100?
I just want the numbers to go 1 to 10 on the top row, then 11-20 on the 2nd row etc.
2 Commenti
James Tursa
il 18 Set 2013
Is this homework? What have you tried so far?
Tom
il 18 Set 2013
Risposta accettata
Più risposte (4)
Another solution using implicit expansion (which wasn't available back in 2013 when this question was posted):
n = 10;
A = (1:n) + n*(0:n-1).'
SYED ABOU ILTAF HUSSAIN
il 2 Set 2018
Modificato: SYED ABOU ILTAF HUSSAIN
il 2 Set 2018
1 voto
Try this a= [1:10]; for i=2:10 a(i,:)=a(i-1,:)+10; end
If we're posting solutions which are instructive, even if not ideal:
A = zeros(10);
A(:) = 1:100;
A = A.'
finess
il 26 Ago 2022
0 voti
create a new 4x4 matrix that is filled with the number 100
9 Commenti
Stephen23
il 26 Ago 2022
"create a new 4x4 matrix that is filled with the number 100"
What did you try so far?
finess
il 27 Ago 2022
I tried to make a matrix A that would print the number 100 a hundred times but It didn't really work well! I am not sure why
A(:)=100
that was it
A = zeros(4,4);
A(:) = 100
finess
il 27 Ago 2022
thanks mhn roberson !
Appreciate that ! would you guys recommend some resources to check out the basics of programming in matlab ! I want learn how to figure out problems in matlab but it keeps puzzling me
finess
il 27 Ago 2022
but again why is the answer the way it is ?
Les Beckham
il 27 Ago 2022
I recommend using this free Matlab training course (link below):
Walter Roberson
il 27 Ago 2022
Modificato: Walter Roberson
il 27 Ago 2022
There are a number of different ways to achieve the same result.
A = 100 + zeros(4,4)
A = 100 * ones(4,4)
A = 100; A = A(ones(4,4))
A = zeros(4,4); A(:) = 100
A(1:4,1:4) = 100
A = repmat(100,4,4)
finess
il 28 Ago 2022
Wow I love these Answers! It gives me a feeling of how a great teacher looks like, with great options for students
Categorie
Scopri di più su Creating and Concatenating Matrices in Centro assistenza e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!