How to insert an array into a matrix?
1 回表示 (過去 30 日間)
古いコメントを表示
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 件のコメント
回答 (1 件)
KALYAN ACHARJYA
2020 年 12 月 11 日
編集済み: KALYAN ACHARJYA
2020 年 12 月 11 日
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.
:)
参考
カテゴリ
Help Center および File Exchange で Creating and Concatenating Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!