Assignment has more non-singleton rhs dimensions than non-singleton subscripts

1 vue (au cours des 30 derniers jours)
yudha sandi
yudha sandi le 6 Juil 2021
Commenté : yudha sandi le 9 Juil 2021
hi i have a problem can help me??
for k = 1:number_of_file
Img = imread(fullfile(name_folder,name_file(k).name));
hsv = rgb2hsv(Img);
v = hsv(:,:,3);
bw = im2bw(v,0.9);
bw = medfilt2(~bw,[5,5]);
bw = imfill(bw,'holes');
bw = bwareaopen(bw,1000);
str = strel('square',10);
bw = imdilate(bw,str);
s = regionprops(bw, 'all');
area = cat(1,s.Area);
perimeter = cat(1,s.Perimeter);
eccentricity = cat(1,s.Eccentricity);
mayor = cat(1,s.MajorAxisLength);
minor = cat(1,s.MinorAxisLength);
character(k,1) = area;
character(k,2) = perimeter;
character(k,3) = eccentricity;
character(k,4) = mayor;
character(k,5) = minor;
end
Assignment has more non-singleton rhs dimensions than non-singleton subscripts
Error in train (line 40)
character(k,1) = area;
anyone can help??

Réponses (1)

Benjamin Kraus
Benjamin Kraus le 6 Juil 2021
Modifié(e) : Benjamin Kraus le 6 Juil 2021
The output from regionprops is a struct array (meaning, there may be more than one region, so the struct array may have multiple entries). It looks like you are accomodating that by calling area = cat(1, s.Area) which is going to create a column vector. But, that means area is a column vector. If area is a column vector and k is a scalar, you are trying to stuff a vector of multiple values into a single location.
You don't indicate in your code what type of variable character is. If you haven't initialized it, it will default to a standard double matrix, and that is likely why you are getting that error.
The way to fix that depends heavilty on your intended goal, but one approach would be to replace character witha cell-array instead of a regular numeric matrix.
k = 1;
character = {};
area = [100;200;300];
character{k,1} = area;

Catégories

En savoir plus sur Resizing and Reshaping Matrices dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by