Adding a linear line of best fit to subplots
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Jonathan O'Neill
am 30 Jan. 2015
Kommentiert: Jonathan O'Neill
am 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 Kommentare
Akzeptierte Antwort
Image Analyst
am 30 Jan. 2015
See my attached polyfit demo. I think it should answer your questions.
1 Kommentar
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Subplots finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!