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
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
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 Center 和 File Exchange 中查找有关 Matrices and Arrays 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!