Creating multiple matrices with linspace
7 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Mike Jane
am 17 Okt. 2020
Kommentiert: Ameer Hamza
am 18 Okt. 2020
Hello all,
I'm trying to create multiple matrices as follows possibly using linspace:
x = [111;111;111]
x = [222;222;222]
x = [333;333;333]
and so on.
I would then use these matrices as a constant in matrix multiplication in an equation.
The reason would be so I don't have to create 100 matrices manually.
Would this be possible without a loop?
Thanks in advance!
2 Kommentare
Stephen23
am 17 Okt. 2020
Bearbeitet: Stephen23
am 17 Okt. 2020
"Would this be possible without a loop?"
One simple and efficient MATLAB approach:
M = [111;111;111].*(1:9)
And then you can trivially access the columns using basic indexing. Hopefully you are not intending to create 100 separate variables in the workspace, which would be about the worst approach for this task: https://www.mathworks.com/matlabcentral/answers/304528-tutorial-why-variables-should-not-be-named-dynamically-eval
Akzeptierte Antwort
Ameer Hamza
am 17 Okt. 2020
Why do you need linspace for this? You can just create such matrices like this
a = [111; 111; 111];
for i = 1:9
x = a*i;
disp(x)
end
2 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!