Adding a linear line of best fit to subplots
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Jonathan O'Neill
le 30 Jan 2015
Commenté : Jonathan O'Neill
le 30 Jan 2015
I have been looking up matlab help on this but I cant seem to get my head around it. For example when I look at my code I just have:
plot (SigVal)
So when I try and plot:
polyval(x, y 1)
I have nothing to put between these brackets except "SigVal". Can someone talk me through how I go about adding a line of best fit to this subplot?
thanks
%-------------------------------------- SIG VAL SUBPLOT -------------------
figure('name','resultimage');
Len=1400;
Wid=600;
aa=25;
bb=200;
set(gcf,'position',[aa bb Len Wid]);
subplot(2,3,1)
xmin=1;
xmax=100;
plot(SigVal)
h=plot(SigVal);
% label max and min values of a 'fn1' on the plot
xValue = get(h,'XData');
yValue = get(h,'YData');
imin = find(min(yValue)==yValue);% find the index for the min and max
imax = find(max(yValue)==yValue);% values of yValue
(yValue(imax));
(yValue(imin));
% label the max. and min. values on the plot
ymax=yValue(imax)+3;
ymin=yValue(imin)-3;
y1=ymax-1;
y2=y1;
y3=ymin+1;
maxstr=['max.=',num2str(yValue(imax))];
minstr=['min.=',num2str(yValue(imin))];
text(10, y1, maxstr);
text(50, y2, minstr);
if Signalstabilitytestfail == 1;
Test_resultstr = 'Test FAILED';
text(30, y3, Test_resultstr)
sigvalteststr='fail';
else
Test_resultstr = 'Test passed';
text(30, y3, Test_resultstr)
sigvalteststr='pass';
%warndlg('Signal Stability failed','!! Warning !!')
end
axis([xmin xmax ymin ymax])
title('SigVal')
0 commentaires
Réponse acceptée
Image Analyst
le 30 Jan 2015
See my attached polyfit demo. I think it should answer your questions.
1 commentaire
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Subplots dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!