plot being generated is not in log space

6 ビュー (過去 30 日間)
M K P Dev
M K P Dev 2021 年 7 月 15 日
コメント済み: M K P Dev 2021 年 7 月 22 日
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:

採用された回答

Cris LaPierre
Cris LaPierre 2021 年 7 月 15 日
編集済み: Cris LaPierre 2021 年 7 月 15 日
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 件のコメント
Cris LaPierre
Cris LaPierre 2021 年 7 月 17 日
編集済み: Cris LaPierre 2021 年 7 月 17 日
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 2021 年 7 月 22 日
thank you cris your answer cleared my doubt

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDevelop Apps Using App Designer についてさらに検索

タグ

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by