Error vertcat not using vertcat

2 views (last 30 days)
Bruno Gonzalo Reynoso
Bruno Gonzalo Reynoso on 23 Sep 2020
Edited: KSSV on 23 Sep 2020
Hello, i´ve used the following line and get the vertcat error
Kx = [407 -169 0 0 0 0 0 0 0 0;-169 331 -162 0 0 0 0 0 0 0; -162 320 -158 0 0 0 0 0 0;0 0 -158 311 -153 0 0 0 0 0;0 0 0 -153 301 -148 0 0 0 0;0 0 0 0 -148 293 -145 0 0 0;0 0 0 0 0 -145 279 -134 0 0;0 0 0 0 0 0 -134 249 -115 0;0 0 0 0 0 0 0 -115 222 -107;0 0 0 0 0 0 0 0 -107 107]
I can´t understand where is the problem since i created the line in excel and it worked perfect for the following line
M=[12.5280326197757 0 0 0 0 0 0 0 0 0;0 12.5280326197757 0 0 0 0 0 0 0 0;0 0 12.5280326197757 0 0 0 0 0 0 0;0 0 0 12.5280326197757 0 0 0 0 0 0;0 0 0 0 12.5280326197757 0 0 0 0 0;0 0 0 0 0 12.5280326197757 0 0 0 0;0 0 0 0 0 0 12.5280326197757 0 0 0;0 0 0 0 0 0 0 12.5280326197757 0 0;0 0 0 0 0 0 0 0 12.5280326197757 0;0 0 0 0 0 0 0 0 0 10.519877675841]
How can i solved it?
  1 Comment
Stephen23
Stephen23 on 23 Sep 2020
Putting all of the data onto one line makes it difficult to debug. If you simply arrange the matrix line-by-line, it is quite obvious that the 3rd row is shorter than all of the other rows:
407 -169 0 0 0 0 0 0 0 0;
-169 331 -162 0 0 0 0 0 0 0;
-162 320 -158 0 0 0 0 0 0; % <- shorter!
0 0 -158 311 -153 0 0 0 0 0;
0 0 0 -153 301 -148 0 0 0 0;
0 0 0 0 -148 293 -145 0 0 0;
0 0 0 0 0 -145 279 -134 0 0;
0 0 0 0 0 0 -134 249 -115 0;
0 0 0 0 0 0 0 -115 222 -107;
0 0 0 0 0 0 0 0 -107 107
To avoid similar errors you should also use delimiting commas rather than spaces.

Sign in to comment.

Accepted Answer

KSSV
KSSV on 23 Sep 2020
Edited: KSSV on 23 Sep 2020
Your matrix is 10*10
Kx = [407 -169 0 0 0 0 0 0 0 0;
-169 331 -162 0 0 0 0 0 0 0;
-162 320 -158 0 0 0 0 0 0; % <-------here there are nine elements
0 0 -158 311 -153 0 0 0 0 0;
0 0 0 -153 301 -148 0 0 0 0;
0 0 0 0 -148 293 -145 0 0 0;
0 0 0 0 0 -145 279 -134 0 0;
0 0 0 0 0 0 -134 249 -115 0;
0 0 0 0 0 0 0 -115 222 -107;
0 0 0 0 0 0 0 0 -107 107]
You have to add an extra zero in 3rd row
Kx = [407 -169 0 0 0 0 0 0 0 0;
-169 331 -162 0 0 0 0 0 0 0;
-162 320 -158 0 0 0 0 0 0 0; % <---- zero added
0 0 -158 311 -153 0 0 0 0 0;
0 0 0 -153 301 -148 0 0 0 0;
0 0 0 0 -148 293 -145 0 0 0;
0 0 0 0 0 -145 279 -134 0 0;
0 0 0 0 0 0 -134 249 -115 0;
0 0 0 0 0 0 0 -115 222 -107;
0 0 0 0 0 0 0 0 -107 107]
Your M matrix was 10*10, all the elements were correct, so it worked. It will work in MATLAB too.

More Answers (0)

Categories

Find more on Matrices and Arrays in Help Center and File Exchange

Tags

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!