I am using a function that I wrote that loads and analyzes time-series data, and plots a figure with subplots if the series contains something interesting.
Here's the plotting part of the code:
if ~isempty(failure_x)
figure(call_n)
sgt = sgtitle(filename);
sgt.FontSize = 10;
subplot(5,1,1)
scatter([1: length(max_vol)], max_vol, '.')
set(subplot(5,1,1), 'XLim', [1, length(max_vol)])
subplot(5,1,2)
scatter([1:length(flow)], flow, '.')
set(subplot(5,1,2), 'XLim', [1, length(max_vol)])
subplot(5,1,3)
scatter([1: length(hlfv)], hlfv, '.')
set(subplot(5,1,3), 'XLim', [1, length(max_vol)])
subplot(5,1,4)
scatter([1: length(stats)], stats(:,2), '.')
set(subplot(5,1,4), 'XLim', [1, length(max_vol)])
subplot(5,1,5)
scatter(failure_x, failure_y)
set(subplot(5,1,5), 'XLim', [1, length(max_vol)])
end
When I call this function by itself from the command line, everything plots properly, but when I call it from a for-loop, the last subplot always seems to be the first subplot from the figure in the next function call from the for loop. Basically, at iteration 1, subplot(5,1,5) shows the data from iteration 2 subpolot(5,1,1).
I added a parameter "call_n" to force the figures to have increasing figure numbers passed in from the for loop, but this didn't seem to solve the problem.
Any ideas? I usually code in python so I'm sure I'm doing something silly.
EDIT: Here is the loop that calls the function "detect_hlfv"
for i = 1:length(fnames)
fname = strcat(data_dir, fnames(i).name);
failures = detect_hlfv(fname, i);
if length(failures) > 0
disp("FAILURE!")
disp(fname);
end
end
forloop (a minimal version thereof) in your code, so that the code reproduces the problem - Luis Mendof = figure(call_n), and then specify this figure object as the parent for the subplotssubplot( 5, 1, 1, 'parent', f )? Similarly you can force subplots to be plot parents...sp = subplot(5,1,1); scatter( sp, x, y );- Wolfie