error using horz cat in app desiner

3 次查看(过去 30 天)
I am trying to make calculation at different range of x based on user input for minimum and maximum also, i added specific calculation y for each x input then i want to put in table and plot in the graph in App desiner but i got error "error using horz cat in app desiner'
Herer is the code
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;
dead=app.uodcpEditField.Value;
uob=app.uobcpEditField.Value;
x=min:100:max;
xn=transpose(x);
if xn==14.7
y=dead;
elseif xn==Pb
y=uob;
elseif xn>Pb
a=-3.9.*(10^-5).*(xn)-5;
m=2.6*(xn.^1.187).*(10.^a);
uob=app.uobcpEditField.Value;
y=uob.*(xn/Pb).^m;
else
y=uob;
end
m=[xn y];
app.UITable.Data=m;
plot(app.UIAxes,xn,y)

回答(1 个)

Simon Chan
Simon Chan 2022-3-25
Variable x is from min:100:max and hence it should not be a single number.
However, varibale y in your code seems to be a single number and hence it gives an error when you use function horzcat.
Adding an index to both variable xn and y as shown below should fix the problem.
x=min:100:max;
xn=transpose(x);
for k = 1:length(x)
if xn(k)==14.7
y(k,1)=dead;
elseif xn(k)==Pb
y(k,1)=uob;
elseif xn(k)>Pb
a=-3.9.*(10^-5).*(xn(k))-5;
m=2.6*(xn(k).^1.187).*(10.^a);
uob=111;
y(k,1)=uob.*(xn(k)/Pb).^m;
else
y(k,1)=uob;
end
end

类别

Help CenterFile Exchange 中查找有关 Develop Apps Using App Designer 的更多信息

产品


版本

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by