Info

此问题已关闭。 请重新打开它进行编辑或回答。

Something funny with Cell Array

3 次查看(过去 30 天)
Andy
Andy 2013-4-20
关闭: MATLAB Answer Bot 2021-8-20
for l=1:dn
bw3 = (dl==l);
[xleft2,xright2,yup2,ydown2] = extract(~bw3);
width2 = xright2-xleft2+1;
height2 = ydown2-yup2;
extractnote=imcrop(bw3,[xleft2,yup2,width2,height2]);
outer_box2 = prop2(l).BoundingBox;
ul_corner_x2 = outer_box2(1);
ul_corner_y2 = outer_box2(2);
box_width2 = outer_box2(3);
box_height2 = outer_box2(4);
notePos=outer_box(2)+outer_box2(2)+(d/2);
noteFromLastline = lastlineF-notePos;
finalnote = pitch(d,gap,noteFromLastline);
output(l) = {finalnote};
end
Hi peeps,
Basically, for the above code I am note getting a filled cell array back.
finalnote gives my n chars back with each looping (i.e. 'A' etc...), but when I add the chars into the output cell array with each loop, at the end I just get an almost empty output cell array with only the first two items filled. This is what I get but I suppose to get all those cells filled. Any help or advice will be greatly appreciated. Thanks.
output =
Columns 1 through 11
'A' 'A' [] [] [] [] [] [] [] [] []
Columns 12 through 22
[] [] [] [] [] [] [] [] [] [] []
Columns 23 through 33
[] [] [] [] [] [] [] [] [] [] []
Columns 34 through 44
[] [] [] [] [] [] [] [] [] [] []
Columns 45 through 46
[] []
  3 个评论
Andy
Andy 2013-4-20
output = cell(1,n);
for p=1:n
bw2 = (L==p);
[xleft,xright,yup,ydown] = extract(~bw2);
width = xright-xleft+1;
height = ydown-yup;
extractbw=imcrop(bw2,[xleft,yup,width,height]);
outer_box = prop1(p).BoundingBox;
ul_corner_x = outer_box(1);
ul_corner_y = outer_box(2);
box_width = outer_box(3);
box_height = outer_box(4);
%--- Extract note heads (Detect the note heads)
se1 = strel('disk',round((d)/2.5),0);
note = imopen(extractbw,se1);
%--- Extract note stems (Detect the note stems)
se1 = strel('line',2*d,90);
stem = imopen(extractbw,se1);
stem = bwmorph(stem,'thin');
stem = imopen(stem,se1);
%--- Pick out note music symbols
if check(note) > 0 && check(stem) > 0 && height < 8*d && width < 2.5*d
%figure;imshow(note);
[dl,dn] = bwlabel(note,8);
prop2 = regionprops(dl,'BoundingBox');
for s = 1:length(prop2)
h(s)=rectangle('Position',prop2(s).BoundingBox);
set(h(s),'EdgeColor','g');
end
for p=1:dn
bw3 = (dl==p);
[xleft2,xright2,yup2,ydown2] = extract(~bw3);
width2 = xright2-xleft2+1;
height2 = ydown2-yup2;
extractnote=imcrop(bw3,[xleft2,yup2,width2,height2]);
outer_box2 = prop2(p).BoundingBox;
ul_corner_x2 = outer_box2(1);
ul_corner_y2 = outer_box2(2);
box_width2 = outer_box2(3);
box_height2 = outer_box2(4);
notePos=outer_box(2)+outer_box2(2)+(d/2);
noteFromLastline = lastlineF-notePos;
finalnote = pitch(d,gap,noteFromLastline)
end
end
end
I initialized output at the top there. Also I changed "l" to "p"
the value of dn fluctuates between 1 and 2 so maybe that is the problem as it keeps assigning values to index 1 and 2 of output cell matrix. However, I am not sure how to fix this though. Please help, thanks.
Image Analyst
Image Analyst 2013-4-20
Too much work for me to analyze, especially without an image, the lack of which prevents me from running your code and replicating your problem. Have you seen this: http://blogs.mathworks.com/videos/2012/07/03/debugging-in-matlab/. Careful debugging on your part will solve this quickly and easily. That is a much more effective route to take than asking us.

回答(1 个)

Walter Roberson
Walter Roberson 2013-4-20
You have "for p = 1 : n", and inside that loop you have a nested loop "for p = 1 : dn". Therefore inside the nested loop, p in the sense of "for p = 1 : n" has its meaning suspended.
Note: if you are looping to n, and inside that you can potentially find multiple objects, then the total number of objects you can find will be more then n. How do you want to deal with that?

此问题已关闭。

Community Treasure Hunt

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

Start Hunting!

Translated by