How to solve the error "Dimensions of arrays being concatenated are not consistent"

7 次查看(过去 30 天)
I have data of size 170x300 and want to create a matrix for the board of Game of Life but keep getting the error:
Error using vertcat
Dimensions of arrays being concatenated are not consistent
This is my code:
load Data %which the data of size 170x300
[N,M]=size(A)
B = zeros(N,N);
v1 = zeros(1,(N+2));
v2 = zeros(M,1);
A = [v1;v2 B v2;v1];
I did the same thing for a matrix of size N = 16 where the code was:
N=16;
B = zeros(N,N);
v1 = zeros(1,(N+2));
v2 = zeros(N,1);
A = [v1;v2 B v2;v1];
which work perfectly. What do I need to do differently for the bigger matrix? All help is appreciated!

回答(1 个)

Walter Roberson
Walter Roberson 2021-2-7
v2 = zeros(N,1);
However, if you are just going to write all over A anyhow, and you are going to do so with the all-zero values, then
A = zeros(size(A,1)+2);
  7 个评论
Walter Roberson
Walter Roberson 2021-2-7
At what point is it saying that i = 2 when you expect it to be 170 ?
You posted that there is an error
Error in celldestiny (line 2)
n = numneighbours(A,i,j)
but you did not show what the error is and you did not show the code for numneighbours()
Watch out, by the way, for numneighbours() vs numneighbors() . "Neighbours" is of course the correct spelling, but we in Canada are quite accustomed to the people in the USA spelling it incorrectly.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Conway's Game of Life 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by