How can I change scaling of my graph depending on the output value?
29 ビュー (過去 30 日間)
古いコメントを表示
Hi, I'm struggling with my appdesigner app. I've written a simple code for bacterial growth (exponential curve). I have an issue with scaling. When I enter the input data and press play, the whole thing works, except when I do this again. When I enter other input data and press play, it works as hold on, which enables the other curve to join the previous one. However, if the value is too big, it doesn't show the other curve on the axis since it's too small. I don't know how to explain myself. The second issue is that I can't find a way to properly set UIAxesLabel values so it's messed up due to the exponential growth. Because the x values can go all the way to millions, however, the xlabel is set to go from 0.1,0,2 and so on and so forth.
Thank you
Peter
properties (Access = private)
rs = [] % Description
Vypis = 0 % Výpis finální hodnoty
end
% Growth
%n = number of bacteria
n = app.BacNumb.Value;
%t = time
t = 0:0.06:app.TimeEditField.Value;
%r = growth in (%)
r = (app.TemporstuSpinner.Value)/100;
app.rs =[app.rs, r];
%b = total number of bacteria (function for exponential growth)
b = zeros(size(t));
%Plot the graph
p_h = plot (app.UIAxes,t,b,'Color','c','LineStyle',':','LineWidth',1.7);
xlim(app.UIAxes,[t(1),t(end)]);
ylim(app.UIAxes,[n,n*exp((max(app.rs).*t(end)))]);
set (app.UIAxes, 'YScale', 'log');
set (app.UIAxes, 'XScale', 'log');
%For i cycle
for i = 1:length(t)
b(i) = n*exp((r.*t(i)));
set(p_h,'YData',b);
drawnow limitrate;
pause(10/length(t));
if (i == length(t))
% app.Vypis = b(i);
app.result.Value = b(i);
sprintf('%0.5f',app.result)
end
end
end
3 件のコメント
採用された回答
Cris LaPierre
2022 年 1 月 17 日
編集済み: Cris LaPierre
2022 年 1 月 17 日
The issue is that, by setting your XTicks manually, you have changed the XTickMode to manual instead of Auto. Therefore, your ticks are not updating when the plot scale changes. In App Designer, select the UIAxes and then, in the property inspector, navigate to TICKS, find the XTickMode property, and change it back to Auto. This will fix your issue.
While here, this is also where you want to set the X and Y scales to log. Expand RULERS and scroll down until you find XScale and YScale. Change the dropdown menu to log.
Now you can delete the following code from your callback.
set (app.UIAxes, 'YScale', 'log');
set (app.UIAxes, 'XScale', 'log');
cla(app.UIAxes)
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Specifying Target for Graphics Output についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!