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

1 回表示 (過去 30 日間)
yudha sandi
yudha sandi 2021 年 7 月 6 日
コメント済み: yudha sandi 2021 年 7 月 9 日
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??

回答 (1 件)

Benjamin Kraus
Benjamin Kraus 2021 年 7 月 6 日
編集済み: Benjamin Kraus 2021 年 7 月 6 日
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;

カテゴリ

Help Center および File ExchangeResizing and Reshaping Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by