필터 지우기
필터 지우기

Function calling in app designer not working

조회 수: 6 (최근 30일)
Riccardo
Riccardo 2024년 2월 15일
이동: Voss 2024년 2월 15일
Hi guys,
I'm coding a matlab script for app designer that when moving a knob it gives back an index that represents the lap's number of a car in a track.
I already posted a question about this code, but only talking in general, not actually providing any of my code, the question is here: https://it.mathworks.com/matlabcentral/answers/2081803-how-to-plot-only-some-part-of-a-vector-based-on-the-index-of-a-knob-in-app-designer i tried everything i could for my if statements but it doesn't work and it also doesn't give me errors, so i really don't know what to do.
I want to plot only a part of a vector (they are all the same lenght) (i want to plot only one lap at the time) by moving the knob, and i have to do for many plots, so the code is kinda long, I can move the Knob but it doesn't change anything, here's the code:
function firstplot(app, ind1, ind2)
plot(app.UIAxes, app.X(ind1:ind2), app.Y(ind1:ind2));
plot(app.UIAxes2, app.TFL(ind1:ind2), 'r');
plot(app.UIAxes2_2, app.TFR(ind1:ind2), 'r');
plot(app.UIAxes2_3, app.TRR(ind1:ind2), 'r');
plot(app.UIAxes2_4, app.TRL(ind1:ind2), 'r');
plot(app.UIAxes2_5, app.WFL(ind1:ind2), 'g');
plot(app.UIAxes2_6, app.WFR(ind1:ind2), 'g');
plot(app.UIAxes2_7, app.WRR(ind1:ind2), 'g');
plot(app.UIAxes2_8, app.WRL(ind1:ind2), 'g');
plot(app.UIAxes2_9, app.alphaFL(ind1:ind2), 'm');
plot(app.UIAxes2_10, app.alphaFR(ind1:ind2), 'm');
plot(app.UIAxes2_11, app.alphaRR(ind1:ind2), 'm');
plot(app.UIAxes2_12, app.alphaRL(ind1:ind2), 'm');
plot(app.UIAxes2_13, app.KFL(ind1:ind2), "Color", "#EDB120");
plot(app.UIAxes2_14, app.KFR(ind1:ind2), "Color", "#EDB120");
plot(app.UIAxes2_15, app.KRR(ind1:ind2), "Color", "#EDB120");
plot(app.UIAxes2_16, app.KRL(ind1:ind2), "Color", "#EDB120");
plot(app.UIAxes2_17, app.FzFL(ind1:ind2), "Color", "#A2142F");
plot(app.UIAxes2_18, app.FzFR(ind1:ind2), "Color", "#A2142F");
plot(app.UIAxes2_19, app.FzRR(ind1:ind2), "Color", "#A2142F");
plot(app.UIAxes2_20, app.FzRL(ind1:ind2), "Color", "#A2142F");
plot(app.UIAxes17, app.r(ind1:ind2), "Color", "#7E2F8E");
plot(app.UIAxes17_2, app.Vx(ind1:ind2), "Color", "#D95319");
plot(app.UIAxes17_3, app.Vy(ind1:ind2), "Color", "#D95319");
plot(app.UIAxes17_4, app.beta(ind1:ind2), "Color", "#77AC30");
end
This is the function to plot every vector in every axes, this function is public.
function startupFcn(app)
app.firstplot(1, length(app.X));
end
This works fine and it always did.
function GiriValueChanged(app, event)
app.giro = app.Giri.Value;
if app.giro==1
app.firstplot(1, app.ind(1));
elseif app.giro==length(app.ind)
app.firstplot(app.ind(end), length(app.X));
elseif (app.giro>=1)&&(app.giro<=length(app.ind))
app.firstplot(app.ind(app.giro-1), app.ind(app.giro));
end
end
And here comes the problem, that's the knob callback, i think this should work but it doesn't, I also tried to create a public function and copy-paste it, but I get the same result.
function RESETButtonPushed(app, event)
app.firstplot(1, length(app.X));
end
Then there's a button that resets the view to the first, the total one, and this works perfectly.
Please guys help me and if you want just give me some advices on good programming on matlab.
Thank you for your time. R
  댓글 수: 2
Voss
Voss 2024년 2월 15일
편집: Voss 2024년 2월 15일
Check is that app.ind is being calculated correctly, i.e., it has the right value and is being updated when it should.
And check that app.Giri.Limits are being set/updated correctly.
Also (this wouldn't fix anything but), if app.Giri.Limits are [1 length(app.ind)], then you can omit the last elseif condition:
function GiriValueChanged(app, event)
app.giro = app.Giri.Value;
if app.giro==1
app.firstplot(1, app.ind(1));
elseif app.giro==length(app.ind)
app.firstplot(app.ind(end), length(app.X));
else
app.firstplot(app.ind(app.giro-1), app.ind(app.giro));
end
end
That is, it's unnecessary to check whether app.giro is >=1 and <=length(app.ind), because you already know it's not 1 and not length(app.ind) by the time the code is there. So it must be >1 and <length(app.ind) by that point. Again, this is supposing that app.Giri.Limits are [1 length(app.ind)], so that app.giro cannot be outside that range, but that's an assumption I'm making and cannot confirm based on the code I can currently see.
Riccardo
Riccardo 2024년 2월 15일
편집: Riccardo 2024년 2월 15일
Thanks for your fast answer,
i checked and app.ind is fine, but when i put a Edit Field (Numeric) with this code on the Knob callback:
function GiriValueChanged(app, event)
app.giro = app.Giri.Value;
app.EditField.Value = double(app.Giri.Value);
...
end
I tried without writing double() but it gives me an error, but the worst part is that i tried and if i click on every value on the knob in that Edit Field it shows numbers from 49 to 54, it's almost like there's a app.Giri.Value+48 , but how??! Can you explain how to solve this?

댓글을 달려면 로그인하십시오.

채택된 답변

Voss
Voss 2024년 2월 15일
이동: Voss 2024년 2월 15일
Seems like app.Giri.Value is a character (which makes sense if it is a 'discrete' uiknob), but you are expecting it to be numeric.
val = '1' % character
val = '1'
double(val)
ans = 49
in which case, you can do
app.giro = app.Giri.Value-'0'; % subtract character '0' from the Value to get the numeric offset from 0
so that, e.g.,
val = '1'
val = '1'
becomes
val-'0'
ans = 1
  댓글 수: 2
Riccardo
Riccardo 2024년 2월 15일
이동: Voss 2024년 2월 15일
Omg it makes so much sense now, thank you, you helped a lot.
How can i "accept" your answer, i can't see the button :(
Voss
Voss 2024년 2월 15일
이동: Voss 2024년 2월 15일
Since that solves the problem, let me change my comment into an Answer and then you can Accept it. Thanks!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Develop Apps Using App Designer에 대해 자세히 알아보기

제품


릴리스

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by