The program doesn't re-read variables's values in Matlab app.designer
6 views (last 30 days)
Show older comments
I made the following program in matlab app.designer.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/486668/image.png)
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
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/486673/image.png)
Then, you click on REFRESH button and the numeric values return to 0 and the text values return to empty.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/486678/image.png)
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.)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/486683/image.png)
The code I have used for CALCULATE button and REFRESH button are those:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/486688/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/486693/image.png)
Thank you very much.
0 Comments
Answers (1)
Rik
on 13 Jan 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 Comments
Rik
on 13 Jan 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.
See Also
Categories
Find more on Develop Apps Using App Designer in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!