error in unrecognized variable or function?

2 views (last 30 days)
I want to make calculation at different x values that yeilds r then plotted and put in table in app designer but the problem that there is error that unrecognized variable or function "r''
here is the code
value = app.minPEditField.Value;
Rs=app.RsSCFSTBEditField.Value;
T=app.TREditField.Value;
API=app.APIEditField.Value;
Pb=app.PbEditField.Value;
P=app.CurrentPressureEditField.Value;
min=app.minPEditField.Value;
max=app.MaxPEditField.Value;
uodead=app.uodcpEditField.Value;
uob=app.uobcpEditField.Value;
for xn=14.7:100:max
switch app.SelectCorrelationDropDown_3.Value
case 'The VASQUEZ-Beggs'
a=-3.9*(10^-5)*(P)-5;
m=2.6*(P^1.187)*(10^a);
uob=app.uobcpEditField.Value;
r=uob*(P/Pb)^m;
case 'Debogh'
x=2.6*(P^1.187)*exp(-11.513-8.98*10^-5*(P))
uob=app.uobcpEditField.Value;
r=uob*(P/Pb)^x;
otherwise
disp("please select correlation")
end
end
v=transpose(xn);
y=transpose(r);
m=[v y];
app.UITable.Data=m;
plot(app.UIAxes,v,y)

Answers (1)

Walter Roberson
Walter Roberson on 25 Mar 2022
1) Your code does not define r for the case where the switch() does not match either case;
2) Your code is not producing one r value per xn value. At the end of the loop, you are going to have a scalar in r (if you have anything)
3) Your results do not depend upon xn at all
4) After a for loop, the loop control variable is left with the last value it was assigned, which would be a scalar in this case. Your context suggest that you are expecting a vector.
  2 Comments
Sam Chak
Sam Chak on 25 Mar 2022
Rather than directly demanding a solution in a blunt manner, it is polite to request for an explanation for each of the comments, so that you get the idea of how to proceed, and rework your code, if you are interested to learn and gain some knowledge or skills from the experience.
If you are interested merely on the solution, you could hire a professional to help, to achieve more in less time.

Sign in to comment.

Categories

Find more on Downloads in Help Center and File Exchange

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!