plot being generated is not in log space

5 visualizzazioni (ultimi 30 giorni)
I am plotting a curve for the following model:
fitfun = fittype(@(a0,a1,x) a0+(a1.*x));
The x and y values are log(x1) and log(y1). I have configures as YScale='log' and XScale='log'
y = [2.091666958,1.929444472,1.954580163,1.903415586,1.875379629,1.875379629,1.903415586,1.875379629,1.942330552,1.903415586,1.903415586,1.929750906,1.942330552]'
x = [7.163732175,7.009281649,5.203296758,7.0004477,7.087439702,7,7.012988611,7.002354474,5.274252552,5.38274806,7.000976802,7,5.321121833]'
UIAxes = uiaxes
UIAxes.XGrid = 'on';
UIAxes.YGrid = 'on';
UIAxes.XMinorGrid = 'on';
UIAxes.YMinorGrid = 'on';
UIAxes.YScale='log';
UIAxes.XScale='log';
starting_x = [1 1];
fitfun = fittype(@(a0,a1,x) a0+(a1.*x));
[fitobject,gof,output] = fit(x,y,fitfun,'StartPoint',starting_x);
fig = figure('Visible','off');
ax = axes(fig);
FigHandle = plot(fitobject,x,y,'or');
hApp = copyobj(FigHandle, UIAxes);
but still the plot which is being plotted is in linear scale and not log scale
I expect the output in log scale:

Risposta accettata

Cris LaPierre
Cris LaPierre il 15 Lug 2021
Modificato: Cris LaPierre il 15 Lug 2021
That's an interesting way to get a plot into a UIAxes. Is there a reason why you don't just plot into it directly?
Your axes are still in log, but by default MATLAB sets the X and Y limits so that your data fills the graph. In your case, there is such little variance in your X and Y data that it looks linear. Set the X and Y limits to [1 10] to convince yourself they are still in log scale.
hApp = copyobj(FigHandle, UIAxes);
ylim(UIAxes,[1 10])
xlim(UIAxes,[1 10])
  3 Commenti
Cris LaPierre
Cris LaPierre il 17 Lug 2021
Modificato: Cris LaPierre il 17 Lug 2021
I assume the issue is that your plot command cannot contain a fit object and a target axes. In this case, you could use feval to create your fit line, then a plot command with a target axis. I'll assume you've added an axes component to your app canvas already, and named it UIAxes
fitfun = fittype(@(a0,a1,x) a0+(a1.*x));
starting_x = [1 1];
fitfun = fittype(@(a0,a1,x) a0+(a1.*x));
[fitobject,gof,output] = fit(x,y,fitfun,'StartPoint',starting_x);
fy = feval(fitobject, x);
loglog(app.UIAxes,x,y,'ro',x,fy,'r-')
ylim(app.UIAxes,[1 10])
xlim(app.UIAxes,[1 10])
M K P Dev
M K P Dev il 22 Lug 2021
thank you cris your answer cleared my doubt

Accedi per commentare.

Più risposte (0)

Tag

Prodotti


Release

R2020a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by