Effacer les filtres
Effacer les filtres

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

7 vues (au cours des 30 derniers jours)
Katara So
Katara So le 7 Fév 2021
Commenté : Steven Lord le 7 Fév 2021
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!

Réponses (1)

Walter Roberson
Walter Roberson le 7 Fév 2021
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 commentaires
Walter Roberson
Walter Roberson le 7 Fév 2021
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.
Steven Lord
Steven Lord le 7 Fév 2021
Sorry, Walter, we haven't finished implementing The Queen's MATLAB yet.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Conway's Game of Life dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by