plot being generated is not in log space
5 次查看(过去 30 天)
显示 更早的评论
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:
0 个评论
采纳的回答
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
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])
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Develop Apps Using App Designer 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!