plot being generated is not in log space
조회 수: 1 (최근 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
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/685473/image.jpeg)
I expect the output in log scale:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/685478/image.jpeg)
댓글 수: 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!