Sorting loop / Cell array issues, plot order..
2 views (last 30 days)
Show older comments
Hey all,
I have a pitch detector program which apart from the final note order sort and plot, works fine..
The issue i have is plotting the filtered and cleaned signal from sine wave melodies..
Below is my code: (small snippet of the problem area):
% SET UP PLOTS..
fig = figure(1);
set (fig, 'Units', 'normalized', 'Position', [0,0,1,1]);
% FOR: LOOP THROUGH ALL 7 NOTES TO CHECK ENDPOINT VALUES..
for cY=1:7
% IF: CHECK THE RANGE OF THE ENDPOINTS..
if (endPOINT(cY) > 50600 && endPOINT(cY) < 51400)
NoteLetter(cY) = 'C';
FreqX(cY) = 261.626;
Position = 1;
% Clean_Sig_Plot{cY} = Clean_Sig{cY};
elseif (endPOINT(cY) > 94600 && endPOINT(cY) < 95300)
NoteLetter(cY) = 'D';
FreqX(cY) = 293.665;
Position = 2;
% Clean_Sig_Plot{cY} = Clean_Sig{cY};
elseif (endPOINT(cY) > 138550 && endPOINT(cY) < 139500)
NoteLetter(cY) = 'E';
FreqX(cY) = 329.628;
Position = 3;
% Clean_Sig_Plot{cY} = Clean_Sig{cY};
elseif (endPOINT(cY) > 183200 && endPOINT(cY) < 183800)
NoteLetter(cY) = 'F';
FreqX(cY) = 349.228;
Position = 4;
% Clean_Sig_Plot{cY} = Clean_Sig{cY};
elseif (endPOINT(cY) > 227100 && endPOINT(cY) < 227800)
NoteLetter(cY) = 'G';
FreqX(cY) = 391.995;
Position = 5;
% Clean_Sig_Plot{cY} = Clean_Sig{cY};
elseif (endPOINT(cY) > 271200 && endPOINT(cY) < 271900)
NoteLetter(cY) = 'A';
FreqX(cY) = 391.995;
Position = 6;
% Clean_Sig_Plot{cY} = Clean_Sig{cY};
elseif (endPOINT(cY) > 308600 && endPOINT(cY) < 309000)
NoteLetter(cY) = 'B';
FreqX(cY) = 493.883;
Position = 7;
% Clean_Sig_Plot{cY} = Clean_Sig{cY};
elseif (endPOINT(cY) <= 0)
msgbox({'Its not working..', num2str(endPOINT(cY)), });
NoteLetter(cY) = 'X';
return;
end
% END IF..
% RESULTS IN THESE MSGBOXs WERE USED TO CHECK CORECT ORDERING OF
% NOTES AGAINST FILTER POSITIONS
% msgbox({'Filter: ',num2str(cY), 'Position: ', num2str(Position), 'Frequency: ', num2str(FreqX{cY}), 'Hz..'});
% CONVERT CLEAN SIGNALS INTO PLOT SIGNALS..
Clean_Sig_Plot{cY} = Clean_Sig{cY};
% CREATE SUBPLOT IN THE CORRECT POSITION..
subplot(7,1,Position), plot(Clean_Sig_Plot(cY));
% SET SUBPLOT PROPERTIES..
xlim([0 310000]);
ylim([0 1]);
ylabel(num2str(cY), 'FontWeight', 'Bold', 'FontSize', 20, 'HorizontalAlignment', 'right', 'VerticalAlignment', 'middle');
set(get(gca,'YLabel'),'Rotation',0)
xXL = 2; yY = 1.4; xXR = 295000;
strFCL = ['Note: ', num2str(NoteLetter(cY)), ' | Frequency: ', num2str(FreqX(cY)), 'Hz..'];
PlottxtL = text(xXL,yY,strFCL,'HorizontalAlignment','left', 'FontWeight', 'Bold');
strFCR = ['The end point for this note is at: ', num2str(endPOINT(cY)), ' | Note Duration: X(samples) / X(s)..'];
PlottxtR = text(xXR,yY,strFCR,'HorizontalAlignment','right', 'FontWeight', 'Bold');
end
% END FOR..
When I run this code, the ylabel of each plot is in the desired order (the sorted order of the different melodies) so i know that's sussed and getting close to what i want to achieve but the main thing is plotting the signals in this same order..
Here are the main issues i have:
1: Clean_Sig{cY} is the cell array of the cleaned and filtered signals. The cY is simply the index of the loop the endpoint checking is in but when i try to plot this:
Clean_Sig_Plot{cY} = Clean_Sig{cY};
subplot(7,1,Position), plot(Clean_Sig_Plot{cY});
This kicks up an error stating cell array to no-cell array etc. I had it working before (although the order wasn't right) so why is this kicking up an error? So to get passed the issue and so it will plot the subplots in the right order, i just wrapped the cY in () rather than {}. Although this doesn't plot anything visible, it allows the empty plots to happen so i can check the order..
2: NoteLetter(cY) = 'C'; When i try to show this variable in the plot text, it displays as the ascii number and not 'C' as wanted. I even used num2str(NoteLetter(cY)) but its still showing it as numbers. Why?
3: NoteLetter, FreqX and endPOINT won't show in the right order although the ylabel text does. Even though i'm using the cY count. Why is this?
Thanks,
Paul..
0 Comments
Answers (0)
See Also
Categories
Find more on Annotations in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!