Clear Filters
Clear Filters

plotting multiple plots in matlab

3 views (last 30 days)
JA
JA on 5 Sep 2016
Commented: dpb on 5 Sep 2016
I am trying to plot a signal which has been filtered with different filters in 1 plot. The only problem is i have to plot the raw signal once and the different filtered signal upon it. handling the color and the legend is getting a mess.
Another main problem is i do not deal with the whole signal at a time. i deal with a segment of the signal at a time. When i say deal with them, it means filtering or plotting.
label{1} = 'raw_Signal'
for i = 1:NumOfFilter
f = FilterClass();
f.fc = x; % fc changes for each filter
for j = 1: length(Signal) % every signal will have multiple segments
filtered_signal = f.eval(signal(j).seg)
plot(handles.axes2, signal(j).time,signal(j).seg,signal(j).time,filtered_signal)
hold(handles.axes2,'on')
end
label{i+1} = 'filter_1'
end
So signal(j).seg is a segment of my raw signal and filtered_signal is the filtered part of signal(j).seg. I need to plot original signal only once and the filtered signal multiple times over that(plotting each segment at once). how do i do this without messing up the legend and color of the signal.

Answers (1)

dpb
dpb on 5 Sep 2016
Plot the raw signal first, then call hold on, then add the other plots to the base. If you'll compute all the results first and store in array by column, plot will treat the array as separate lines automagically and cycle colors and legend will be in sequence as well.
If the plot segments aren't all the same length, start with NaN array of proper maximum size and place the data in it; the NaN values won't be plotted.
  2 Comments
JA
JA on 5 Sep 2016
That's what i do now, 1st i plot the signal, and set the hold to on. Then i filter all segments of all signal and store it in an array. Then i start plotting them. but the problem is with the color of the plot. the raw signal and the 1st plot have same color.
dpb
dpb on 5 Sep 2016
That doesn't appear to be precisely that to me but it's awfully confusing so didn't try to pursue it too much in depth...
But, my bad, I typed hold on when intended hold all; the latter form is the one that causes the color order to not restart but to be retained...
Of course, if you'll save the line handles of the segments, you can set the colors to whatever you wish or you can create a color array and use it in the initial plot to set the color as desired on creation. I suspect you'll have to do one or t'other to get the desired effect anyways as you're likely going to run out of the number of default colors available.

Sign in to comment.

Tags

Community Treasure Hunt

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

Start Hunting!