English 中文(简体)
MATLAB错误:功能子指数没有为等级结构的数值确定
原标题:MATLAB error: Function subsindex is not defined for values of class struct
  • 时间:2012-04-08 08:00:45
  •  标签:
  • matlab

我审判了这些指挥官:

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;

(在我有另一条指挥线的地方,但我猜测问题不是因为如此)

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

I got this error message:

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

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

什么是错的?

最佳回答

你之所以重新发现这一错误,是因为你创造了一个variable <>/em>的“size”,即“size”的影子,即:SIZE。 http://www.un.org a) 将结构变量(如错误信息所示)作为指数。

总的来说,你应当给出一个变数或功能,说明现有职能的名称(除非您,了解你重新做什么)。 仅将你代码中的变量名称改为“大小”之外的其他内容,发布指令clear small ,以清除工作空间的旧尺寸变量,并改写你的代码。

问题回答

你的错误信息告诉你,这一错误在<代码>编号OfBlobs = 大小(blobMeasurements, 1);subsindex最有可能在<代码>size(......, 1)上用于查阅这些内容。

我假定,<条码>blobMeasurements是一系列的构件(或单一构件),对这些行动没有完全界定。

为什么没有像以前那样使用<代码>length指挥? 这在你们的法典中是很早的。





相关问题
MATLAB Solving equations problem

I want to solve these equations using MATLAB and I am sure there is a non zero solution. The equations are: 0.7071*x + 0.7071*z = x -0.5*x + 0.7071*y + 0.5*z = y -0.5*x - 0.7071*y +...

Difference between MATLAB s matrix notations

How do you read the following MATLAB codes? #1 K>> [p,d]=eig(A) // Not sure about the syntax. p = 0.5257 -0.8507 -0.8507 -0.5257 d = ...

preventing data from being freed when vector goes out of scope

Is there a way to transfer ownership of the data contained in a std::vector (pointed to by, say T*data) into another construct, preventing having "data" become a dangling pointer after the vector goes ...

Divide two polynomials using MATLAB

I want to divide p(x) by q(x) given that: p(x)=-5x^4+3x^2-6x q(x)=x^2+1 I tried: p=inline( -5*(x^4)+3*(x^2) , x ) p = Inline function: p(x) = -5*(x^4)+3*(x^2) q=inline( x^2+1 , x ) q = ...

matlab deals with Fibbonacci

The Fibonacci series is given as follows: 1, 2, 3, 5, 8, 13, 21, ... How can I write a script which calculates and prints the n-th Fibonacci term (for n>2), where n is inputed by the user. This ...

How do I plot lines between all points in a vector?

I have a vector containing some points in 2-D space. I want MATLAB to plot these points with lines drawn from every point to every other point. Basically, I want a graph with all vertices connected. ...

How do I create a string using a loop variable in MATLAB?

I have a loop like this: for i=1:no %some calculations fid = fopen( c:\out.txt , wt ); %write something to the file fclose(fid); end I want data to be written to different files like ...

热门标签