the first attempt of this is I just want the user inputs to reflect in the script. If this is successful then I can try to take it a step futher and have it run the script after the inputs are made. But for now I am just trying to at least modify the variables based on what the user selects from the GUI.
Create a GUI to change variables in a script
6 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I'm trying to create a GUI to change variables in a script based on user selection.
For example I have a j function and a line reads as:
j.fastener = Bolt(bolt_size, bolt_material, bolt_length);
but I want to create a GUI that will change
bolt_size
bolt_material
bolt length
based on what the user selects

so say the user selects the above options,
then based on these inputs, the variables in the script should change to
j.fastener = Bolt('10-32', 'A286', .125);
So I am trying to get inputs from a use to change the variables of the script itself based on the selection.
6 commentaires
John D'Errico
le 14 Mar 2024
Modifié(e) : John D'Errico
le 14 Mar 2024
Learn to use functions. Then you can pass in any variables you want. Your code need never change on the fly, a terribly bad idea in general.
As far as how to change a variable contents based on what you pass in, that part is trivial. It is the essence of what a function does!
myfun('First time called')
myfun('Second time called')
function myfun(b)
b
end
Do you see that b takes on the value you pass in?
Réponses (1)
Ishaan Mehta
le 26 Déc 2024
Hi Ryan,
You can create a MATLAB function that thakes the 3 inputs, namely, bolt_size, bolt_material, and bolt length, and assign its result to "j.fastener".
A MATLAB function is a defined block of code encapsulated within a separate .m file, designed to perform a specific computational task. It consists of a function signature that specifies the function's name, input arguments, and output arguments. The function body contains executable statements that implement the desired operations using the input parameters to produce the outputs.
Learn more about creating MATLAB functions here: https://www.mathworks.com/help/matlab/ref/function.html
As an alternative to creating an application using MATLAB App Designer, you can create a simple MATLAB live script that takes in input values as dropdowns within the script itself, and then uses the selected values in the code that follows, as descibed in the below documentation page:
Add Interactive Controls to a Live Script: https://www.mathworks.com/help/matlab/matlab_prog/add-interactive-controls-to-a-live-script.html#:~:text=the%20date%20picker.-,Drop%2DDown%20List,-Use%20a%20drop
It would ideally look similar to the image below:

Hope this helps!
0 commentaires
Voir également
Catégories
En savoir plus sur Develop Apps Using App Designer dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!