How to insert an array into a matrix?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
I have the following code:
lon = xlsread('datatrial.xlsx','A1:A2');
Nsteps=2
for i=1:Nsteps
P_ini=[lon, 2 ,1];
end
-Where I want to get two different matrices eg. P_ini= [A1,2,1] & [A2,2,1]
-The error I get is:Dimensions of arrays being concatenated are not consistent.
I need to do it for larger ranges therefore I would love to learn the way to do it.
Thank you.
0 comentarios
Respuestas (1)
KALYAN ACHARJYA
el 11 de Dic. de 2020
Editada: KALYAN ACHARJYA
el 11 de Dic. de 2020
In the it read the two cell elements from the excel file
lon = xlsread('datatrial.xlsx','A1:A2');
Hence the resultant "lon" will be 2x1
>> whos Ion
Name Size Bytes Class Attributes
Ion 2x1 16 double
Next within the for loop, ion horizontal concatenate with two number (scalar)
P_ini=[lon, 2 ,1];
Which is the dimention issue, as Ion is 2x1, next two numbers, how can you do that?? But yes you can do the vertical concatenate with the nnumbers, likewise
P_ini=[lon;2;1];
As a result P_ini will be 4x1 row vector.
More: In each iteration, you can save the vector result in cell array P_ini, in such case
P_ini=cell(4,1);
for
P_ini{i}=...
end
Also, you can avoid the loop here and draw two vectors directly.
:)
Ver también
Categorías
Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!