MATLAB错误:未为类"struct"的值定义函数"subsindex" [英] MATLAB error: Function 'subsindex' is not defined for values of class 'struct'

查看:1771
本文介绍了MATLAB错误:未为类"struct"的值定义函数"subsindex"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试了以下命令:

im=imread('untitled_test1.jpg');
im1=rgb2gray(im);
im1=medfilt2(im1,[15 15]);
BW = edge(im1,'sobel'); 

msk=[0 0 0 0 0;
 0 1 1 1 0;
 0 1 1 1 0;
 0 1 1 1 0;
 0 0 0 0 0;];
B=conv2(double(BW),double(msk));

Ibw = im2bw(B);
CC = bwconncomp(Ibw); %Ibw is my binary image
stats = regionprops(CC,'pixellist');

% pass all over the stats
for i=1:length(stats),
size = length(stats(i).PixelList);
% check only the relevant stats (the black ellipses)
if size >150 && size < 600 
    % fill the black pixel by white    

    x = round(mean(stats(i).PixelList(:,2)));
    y = round(mean(stats(i).PixelList(:,1)));
    Ibw = imfill(Ibw, [x, y]);

else
    Ibw([CC.PixelIdxList{i}]) = false;
end;
end;

(这里有另一个命令行,但我想问题不在于它们.)

(here I have another command lines, but I guess the problem is not because of them.)

labeledImage = bwlabel(binaryImage, 8);     % Label each blob so we can make measurements of it
blobMeasurements = regionprops(labeledImage, Ibw, 'all');   
numberOfBlobs = size(blobMeasurements, 1); 

我收到此错误消息:

??? Error using ==> subsindex
Function 'subsindex' is not defined for values of class 'struct'.

Error in ==> test2 at 129
numberOfBlobs = size(blobMeasurements, 1);

怎么了?

推荐答案

由于创建了一个名为"size"的变量,它掩盖了内置的函数,因此出现此错误 尺寸. MATLAB并未调用函数来计算numberOfBlobs,而是尝试使用结构blobMeasurements作为索引来对变量 index 进行索引(这不起作用,因为错误消息显示.)

You're getting that error because you have created a variable called "size" which shadows the built-in function SIZE. Instead of calling the function to compute numberOfBlobs, MATLAB instead tries to index the variable using the structure blobMeasurements as an index (which doesn't work, as the error message shows).

通常,您不应给变量或函数一个已经存在的函数的名称(除非您

In general, you shouldn't give a variable or function the name of an already existing function (unless you know what you're doing). Just change the name of the variable in your code to something other than "size", issue the command clear size to clear the old size variable from the workspace, and rerun your code.

这篇关于MATLAB错误:未为类"struct"的值定义函数"subsindex"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆