Hello,
I have mutiple datasets that are ploted within a for loop in the same subplot of a figure.
Like:
nameIndexGears = fieldnames(struct)
for i = 1:length(nameIndexGears)
subplot 211
hold on
plot(struct.(nameIndexGears{i}).data, y)
hold off
subplot 212
plot(a,b)
end
I also want to plot a fit in the same subplot as the data.
fitresult_1 = fit (allGears, y, 'poly1')
nameIndexGears = fieldnames(struct)
for i = 1:length(nameIndexGears)
subplot 211
hold on
plot(struct.(nameIndexGears{i}).data, y)
plot(fitresult_1, 'predobs')
hold off
subplot 212
plot(a,b)
end
Ploting the fitresult does work, but sadly the ploting of the gears does not work anymore. It only plots the data of the last gear. I figured out, that in the first case matlab preprocesses the figure and then opens it. As soon as i add the cfit plot it directly opens the figure and changes it on evry loop as a consequence of which the gears overwrite themself on each repetition.
I tried various positions of my hold on and hold off comands but that doesn't change a thing. Also I tried refering to the axes in the plot line like:
subplot 211
hold on
ax1 = gca;
plot(ax1, x, y)
plot(ax1, fitresult_1, 'predobs')
hold off
Sadly the cff/plot does not support refering to a current axis.
Here are two examples of my plots:
As described i would like to have the fitted curve in the first plot.
Does anyone know a solution for this case?
Thanks in advance!
Simon