How to create multiple matrices using for loop?

5 Ansichten (letzte 30 Tage)
Rohit Raut
Rohit Raut am 17 Apr. 2021
Kommentiert: Jonas am 18 Apr. 2021
How to take input of coordinates of n number of points and store it in different 2x1 matrices?
The loops I am using are as follows but there is some error.
for i=1:n
x(i)=input('Enter the X-coordinate of node ')
y(i)=input('Enter the Y-coordinate of node ')
end
C=[x;y]
for i=1:n
P(i)= [x(i);y(i)]
end
  8 Kommentare
Stephen23
Stephen23 am 18 Apr. 2021
"I know it is bad programming style, but Rohit Raut wants multiple 2x1 matrices P1,P2..."
A cell array already contains those "multiple matrices", which are trivially accessible via indexing.
Jonas
Jonas am 18 Apr. 2021
i'm a bit confused what you really want. If u are ok with multiple 2x1 matrices in a cell array you can just use num2cell(C,1) in your case, it divides a 2 x n matrix into n cells containing each 2x1 matrices

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by