Dimensions of matrices being concatenated are not consistent.

97 次查看(过去 30 天)
letters=['a'; 'b'; 'c'; 'd'; 'e'; 'f'; 'g'; 'h'; 'i'; 'j'; 'k'; 'l'; 'm'; 'n'; 'o' ;'p'; 'q'; 'r'; 's'; 't' ; 'u' ;'v' ;'w'; 'x' ;'y'; 'z'; 'aa'; 'bb'; 'cc'; 'dd'; 'ee'; 'ff'; 'gg'; 'hh'; 'ii'; 'jj'; 'kk'; 'll'; 'mm'; 'nn'; 'oo'; 'pp'; 'qq'; 'rr'; 'ss'; 'tt'; 'uu'; 'vv'; 'ww'; 'xx'; 'yy'; 'zz'; 'num0'; 'num1'; 'num2'; 'num3'; 'num4'; 'num5'; 'num6'; 'num7'; 'num8'; 'num9'];
increment =1;
for y = 1: 62
for k = 1 : 10
test = strcat(letters(y,:) , num2str(k));
addpath 'C:\Users\Lenovo\Downloads\Documents\Mathworks Matlab 2016a (9.0.0.341360) x64(1)\Matlab-2016a-Win64-Crack\R2016a\bin\FeatureExtraction'
imageName = imread(['training_set',test,'.png']);
imageName = rgb2gray(imageName);
x(:, increment) = (feature_extract(~im2bw(imageName)));
increment = increment + 1;
end;
end;
x = x';
I want to store this in a matrix, i keep getting the error dimensions are not consistent. Please help

采纳的回答

KL
KL 2017-12-4
The error comes from your very first line when you're trying to create a char array called letter. Look at this example,
>> letters = ['a';'b';'c']
letters =
3×1 char array
'a'
'b'
'c'
now just add one more character to the last element,
>> letters = ['a';'b';'cc']
Dimensions of matrices being concatenated are not consistent.
do you see what's the problem? it's simply similar to numeric matrices. You cannot have one element more in just one row. In other words, the width of all the rows must be equal.
One alternative to this would be to declare that variable as a cell array,
>> letters = {'a';'b';'cc'}
letters =
3×1 cell array
'a'
'b'
'cc'
read about them by typing doc cell

更多回答(1 个)

Mudassir shakeel
Mudassir shakeel 2022-3-19
This error occured only when the dimensions of matrices are not same, like the entiites in each column must be same size

类别

Help CenterFile Exchange 中查找有关 Data Types 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by