Function calling in app designer not working
9 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Voss
le 15 Fév 2024
Modifié(e) : Voss
le 15 Fév 2024
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.
Réponse acceptée
Voss
le 15 Fév 2024
Déplacé(e) : Voss
le 15 Fév 2024
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
double(val)
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'
becomes
val-'0'
2 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Develop Apps Using App Designer dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!