필터 지우기
필터 지우기

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