Borrar filtros
Borrar filtros

Info

La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.

Something funny with Cell Array

3 visualizaciones (últimos 30 días)
Andy
Andy el 20 de Abr. de 2013
Cerrada: MATLAB Answer Bot el 20 de Ag. de 2021
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 comentarios
Andy
Andy el 20 de Abr. de 2013
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 el 20 de Abr. de 2013
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.

Respuestas (1)

Walter Roberson
Walter Roberson el 20 de Abr. de 2013
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?

La pregunta está cerrada.

Community Treasure Hunt

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

Start Hunting!

Translated by