Why do I encounter error using vertcat?

7 ビュー (過去 30 日間)
Mark Cuanan
Mark Cuanan 2018 年 3 月 21 日
コメント済み: Mark Cuanan 2018 年 3 月 21 日
I want to have mass 9x9 diagonal matrix (mass matrix) and 9x9 stiffness matrix. The code goes like this:
m1= getappdata(handles.mass1_edittxt , 'm1');
m2= getappdata(handles.mass2_edittxt , 'm2');
m3= getappdata(handles.mass3_edittxt , 'm3');
m4= getappdata(handles.mass4_edittxt , 'm4');
m5= getappdata(handles.mass5_edittxt , 'm5');
m6= getappdata(handles.mass6_edittxt , 'm6');
m7= getappdata(handles.mass7_edittxt , 'm7');
m8= getappdata(handles.mass8_edittxt , 'm8');
m9= getappdata(handles.mass9_edittxt , 'm3');
k1= getappdata(handles.stiff1_edittxt , 'k1');
k2= getappdata(handles.stiff2_edittxt , 'k2');
k3= getappdata(handles.stiff4_edittxt , 'k3');
k4= getappdata(handles.stiff4_edittxt , 'k4');
k5= getappdata(handles.stiff4_edittxt , 'k5');
k6= getappdata(handles.stiff4_edittxt , 'k6');
k7= getappdata(handles.stiff4_edittxt , 'k7');
k8= getappdata(handles.stiff4_edittxt , 'k8');
k9= getappdata(handles.stiff4_edittxt , 'k9');
d= getappdata(handles.dampRatio_edittxt,'d');
M=diag([m1 m2 m3 m4 m5 m6 m7 m8 m9]);
k=vertcat([k1 -k1 0 0 0 0 0 0 0;-k1 (k1+k2) -k2 0 0 0 0 0 0;0 -k2 (k2+k3) -k3 0 0 0 0 0;0 0 -k3 (k3+k4) -k4 0 0 0 0;0 0 0 -k4 (k4+k5) -k5 0 0 0;0 0 0 0 -k5 (k5+k6) -k6 0 0;0 0 0 0 0 -k6 (k6+k7) -k7 0;0 0 0 0 0 0 -k7 (k7+k8) -k8;0 0 0 0 0 0 0 -k8 (k8+k9)]);
Can anyone help me why this code shows error as follows:
Error using vertcat
Dimensions of matrices being concatenated are not consistent.
Error in finally>calculatemodeshape_button_Callback (line 336)
k=vertcat([k1 -k1 0 0 0 0 0 0 0;-k1 (k1+k2) -k2 0 0 0 0 0 0;0 -k2 (k2+k3) -k3 0 0 0 0 0;0 0 -k3 (k3+k4) -k4 0 0 0 0;0 0 0
-k4 (k4+k5) -k5 0 0 0;0 0 0 0 -k5 (k5+k6) -k6 0 0;0 0 0 0 0 -k6 (k6+k7) -k7 0;0 0 0 0 0 0 -k7 (k7+k8) -k8;0 0 0 0 0 0 0 -k8
(k8+k9)]);
  2 件のコメント
KSSV
KSSV 2018 年 3 月 21 日
Check the dimensions of matrices sent to vertcat they are not compatible for joining.
Mark Cuanan
Mark Cuanan 2018 年 3 月 21 日
These are the files. Please check the error. I already check the dimensions of matrices and see to it that it is 9x9 matrix.

サインインしてコメントする。

採用された回答

Walter Roberson
Walter Roberson 2018 年 3 月 21 日
If you getappdata() of a variable that has not been stored into the appdata, then there will not be an error message, and instead [] will be returned. When you [] together the list of variables and that empty variable is substituted in, vertcat does not substitute 0 and does not leave a hole: it assumes you might have wanted the array to be empty and proceed to try to put all the rows together (but they are different sizes and it cannot do so.)
By the way, you do not need to call vertcat() because the [] operator already implies vertcat and horzcat as needed.
  1 件のコメント
Mark Cuanan
Mark Cuanan 2018 年 3 月 21 日
Here is the edited one. I am a really need a help. Please do comment on what is the error.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by