The same script works perfectly on Matlab and does not on app designer

I have made a code which the user enters as inputs several variables and when running the code, it (the code) calls several scripts to calculate the oututs. If I execute it on command window or even in the script itself, it works perfectly.
The point is that I am implementing it on matlab app designer. In an app that when you click the button, the code calls the scripts and the program gives the outputs to the user. So, here, when the code calls one of the scripts called "jENG000_ca1", matlab gives me the following error on the jENG000_ca1 script's line 53.
Here is exactly the code in that line:
if (epsilon==6969)&&(m~=6969)&&(alfa~=6969)&&(R1~=6969)&&(R2~=6969)&&(Rb1~=6969)&&(Rb2~=6969)&&(Rc1~=6969)&&(Rc2~=6969) %line 53
[epsilon,R1,R2,Rc1,Rc2,ro1,ro2,alfa,m]=epsilon00(epsilon,R1,R2,Rc1,Rc2,ro1,ro2,alfa,m) %line 54
end %line 55
I have tried also with the parenthesis (as you can see in the image) and without them and it works perfectly on matlab and on the script, but as you can see, does not work in matlab app designer.
How can I solve this? As long as I know, I am not doing anything wrong.
Thanks a lot

 Accepted Answer

My guess is that when you call the function in the Command Window or script you're calling it on scalar data but when you call it in App Designer you're calling it with non-scalar data.
This could happen if one or more of the variables epsilon, m, alfa, R1, R2, Rb1, Rb2, Rc1, or Rc2 are being read from an edit box in the app and are being read not as numeric data but as text.
A1 = '12345';
A2 = 12345;
A1 == A2 % None of the characters '1', '2', '3', '4', or '5' are equal to 12345
ans = 1x5 logical array
0 0 0 0 0
whos A1 A2
Name Size Bytes Class Attributes A1 1x5 10 char A2 1x1 8 double
If that's the case, convert the text data to numbers.
A3 = str2double(A1);
A2 == A3
ans = logical
1
whos A1 A2 A3
Name Size Bytes Class Attributes A1 1x5 10 char A2 1x1 8 double A3 1x1 8 double

5 Comments

Thanks for answering!
The values of the input variables are introduced in the app via EditField(text) and they are converted into numeric elements with the command str2num. Here is not the issue (I think) , because I have checked those variables with commands whos and class() and they all are 'double'. Also, The program works fine with those variables in the first scripts, the only issue is in the line 53 of that specific script (jENG000_ca1).
The class of the variables is important, but so is the size.
x = 1:5;
y = x && true
Operands to the || and && operators must be convertible to logical scalar values.
The problem here is that x is not scalar.
Thanks a lot for your reply!
I have just checked also their sizes and all of them are 1x1. And class double also of course
Those are the variables that the user enters in the program, all of them are 1x1 and double as you can see.
Also, as I said before, the code calls several scripts, all of them work perfectly and calculates perfectly the output variables until the code calls the script jENG000_ca1, when matlab says the error of the line 53 that I have said before
The line of code you posted uses the following variables: epsilon, m, alfa, R1, R2, Rb1, Rb2, Rc1, or Rc2. You've shown two of these variables (alfa and m) but not the other seven.
Let's check the sizes using the debugger. Set an error breakpoint and attempt to reproduce the problem. If you can, you will enter debug mode (a K>> prompt in the Command Window.) Look at the line of code where the problem occurred and look at all the variables and functions used on that line.
I have found the issue.
The point is that epsilon wasn't defined, so it had no value, thus, it was a 0x0 size variable. Once I define the value of epsilon (as it was supposed to work like), the problem is resolved
Thanks for the help!

Sign in to comment.

More Answers (0)

Categories

Find more on Develop Apps Using App Designer in Help Center and File Exchange

Products

Release

R2019b

Community Treasure Hunt

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

Start Hunting!