Error vertcat not using vertcat

2 次查看(过去 30 天)
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 个评论
Stephen23
Stephen23 2020-9-23
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.

请先登录,再进行评论。

采纳的回答

KSSV
KSSV 2020-9-23
编辑:KSSV 2020-9-23
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.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Matrices and Arrays 的更多信息

标签

产品


版本

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by