How can I change scaling of my graph depending on the output value?

29 ビュー (過去 30 日間)
Petr Masek
Petr Masek 2022 年 1 月 16 日
編集済み: Cris LaPierre 2022 年 1 月 17 日
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 件のコメント
Petr Masek
Petr Masek 2022 年 1 月 17 日
編集済み: Petr Masek 2022 年 1 月 17 日
Here is the whole code. I think there's something wrong with the UIAxesLabel (probably ticks) in the design view which you can't unfortunatelly see.
Thanks for the answer
Edit: I've also included the whole application. I don't care if someone use it, it's a personal project.
I'm sorry, the app is not in English.
Petr Masek
Petr Masek 2022 年 1 月 17 日
You are right, the limits have been causing the scaling, but now, what about the x-axis ticks. It stops at 10 and doesn't go towards the bigger numbers.
Thank you very much in advance
Peter

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

採用された回答

Cris LaPierre
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');
One more suggestion. I think a better way to clear you graph (lines 86-87) is to use cla.
cla(app.UIAxes)
  1 件のコメント
Petr Masek
Petr Masek 2022 年 1 月 17 日
Thank you, wow, I could have figured this out on my own.
Thanks again :-)

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSpecifying Target for Graphics Output についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by