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) %Plots the data of 4 gears in one subplot
hold off subplot 212 plot(a,b) % plots something else
end
I also want to plot a fit in the same subplot as the data.
fitresult_1 = fit (allGears, y, 'poly1') % allGears is a concatenated Vector of all gears
nameIndexGears = fieldnames(struct)for i = 1:length(nameIndexGears) subplot 211 hold on plot(struct.(nameIndexGears{i}).data, y) %Plots the data of 4 gears in one subplot plot(fitresult_1, 'predobs') % plots the fitresults with the predictionbounds
hold off subplot 212 plot(a,b) % plots something elseend
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 211hold onax1 = 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
Best Answer