Plot line of best fit for semilog plot
Ältere Kommentare anzeigen
Hi everyone,
So I have seen a few answers on here similar to the question I am asking but I cannot seem to apply the solutions sucessfully.
The code here is with made up numbers but the magnitude of jump between the data is reprasentative of the real thing.
PM on the x-axis increases linearly but RS on the Y-axis does not. I have applied a log scale to the y-axis and attempted to fit a line of best fit but the line is not sitting well with the data and I get a 'negative values ignored' warning?
Any help much appreciated!!
RS = [1, 0.2, 0.15, 0.1, 0.05];
PM = [1, 2, 3, 4, 5];
pmS = polyfit(PM,log(RS),2);
rs = polyval(pmS,PM);
figure('Units', 'pixels', ...
'Position', [100 200 500 375]);
hold on
sfitRS = line(PM,RS);
set(sfitRS,...
'LineStyle','none',...
'Marker','o',...
'MarkerSize',10,...
'MarkerEdgeColor',[0.3 0.3 0.3])
hold on
LOBF = plot(PM,rs); %line of best fit
set(gca, ...
'XMinorTick' , 'on' , ...
'YMinorTick' , 'on' , ...
'XGrid' , 'on' , ...
'YGrid' , 'on' , ...
'YScale' , 'log' , ...
'LineWidth' , 1 );
1 Kommentar
jessupj
am 1 Mai 2020
if anything you've plotted in 'regular' coordinates has negative y values, imposing a log scale on the yaxis in effect is attempting to take the logarithm of negative numbers.
it looks like your line of best fit is already logarithmically transformed, since your pmS is fit to the log of the numbers.
look at:
plot(PM,log(RS),'ok','MarkerSize',10,'MarkerEdgeColor',[0.3 0.3 0.3])
hold on
plot(PM,rs); %line of best fit
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Interpolation finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!