Why do I encounter error using vertcat?

7 vues (au cours des 30 derniers jours)
Mark Cuanan
Mark Cuanan le 21 Mar 2018
Commenté : Mark Cuanan le 21 Mar 2018
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 commentaires
KSSV
KSSV le 21 Mar 2018
Check the dimensions of matrices sent to vertcat they are not compatible for joining.
Mark Cuanan
Mark Cuanan le 21 Mar 2018
These are the files. Please check the error. I already check the dimensions of matrices and see to it that it is 9x9 matrix.

Connectez-vous pour commenter.

Réponse acceptée

Walter Roberson
Walter Roberson le 21 Mar 2018
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 commentaire
Mark Cuanan
Mark Cuanan le 21 Mar 2018
Here is the edited one. I am a really need a help. Please do comment on what is the error.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by