The program doesn't re-read variables's values in Matlab app.designer

2 visualizaciones (últimos 30 días)
I made the following program in matlab app.designer.
The point here is that you introduce the variables "m" and "a" in whatever editfields on the left and their numeric values in whatever fields on the right.
Then, by clicking on CALCULATE button it appears the value of the Force (F=m*a) in the centre as you can see in the image
Then, you click on REFRESH button and the numeric values return to 0 and the text values return to empty.
Everything goes fine right to that point.
The issue here is that after clicking on REFRESH, and I want to introduce again variables and values...the program no longer reads the variables and their values, so the program doesn't calculate the value of the force of course. Just it doesn't do anything and appears that error on the command window. (By the way, app's code goes just until line 155, I don't know what that line 335 means.)
The code I have used for CALCULATE button and REFRESH button are those:
Thank you very much.

Respuestas (1)

Rik
Rik el 13 de En. de 2021
You should probably consider stripping all whitespace from the user input.
This looks to me like the value in the text field is not equal to either of your branches, meaning m is not defined. You are also using == to compare char arrays, instead of strcmp (which would also handle strings and will handle arrays of dissimilar size).
switch app.text1.Value
case 'm'
m=app.num1.Value;
case 'a'
a=app.num1.Value;
otherwise
%make sure your user gets an error here, or set default values
end
Another possibility is to use a dropdown menu or radio buttons to allow the user to select variables.
  2 comentarios
ErikJon Pérez Mardaras
ErikJon Pérez Mardaras el 13 de En. de 2021
Thanks for your reply. I have tried your code and the same happens. First it does well, but when I click refresh and try to do it the second ime, doesn't caluclate it and again appears that 'm' is unrecognized.
However I have tried with drop down menus and it doesn't even work the first time. I don't know where I am doing wrong here.
This is what appears in the command window when I click the CALCULATE button.
Rik
Rik el 13 de En. de 2021
You assume both time that the user meant to write 'a'. If you have ' a' and ' m', both branches will define a, leaving m undefined. You also made a copy-paste error: in the second case you probably mean val1 instead of val2.
Since you only post image, instead of a code file, I can't see what your refresh button is doing, nor what you attempted to do with the dropdown. The dropdown (or radio button) will work if properly implemented and will make sure your user can't mess it up by writing 'ma' in one of the fields.

Iniciar sesión para comentar.

Categorías

Más información sobre Develop Apps Using App Designer en Help Center y File Exchange.

Productos


Versión

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by