필터 지우기
필터 지우기

Why do I receive the error "Undefined function 'times' for input arguments of type 'matlab.gr​aphics.cha​rt.primiti​ve.Line'"?

조회 수: 5 (최근 30일)
I am using the App Designer to create a GUI and am running into an issue with my portion of the code that limits the x axis on a plot in the app (section commented "Adjust axis for radial profile" in code). When I transferred the code to a normal code file, removed the inputs from the app's sliders, inputted substitute values, and ran it, it worked fine. I have checked my functions and code many times, but otherwise I am out of things to try as I have no idea what this error means.
% App Designer code
% Set up plotting options menu
app.PlotmagnitudeCheckBox.Value = 1;
app.PlothorizontalvelocityCheckBox.Value = 1;
app.PlotverticalvelocityCheckBox.Value = 1;
app.FixedParametersCheckBox.Value = 1;
% Define parameters for radial profile
t = app.TimeofstormSlider.Value;
for t_int = app.IntensificationtimeSlider.Value
if t <= t_int
p = t / t_int;
else
p = exp((-(t-t_int))/11.542);
end
end
r = 0:0.1:10000;
z = app.zSlider.Value;
r_max = app.MaxrSlider.Value * 1000;
z_max = app.MaxzSlider.Value;
ur_max = app.MaxoutflowvelSlider.Value;
u_trans = app.utransSlider.Value;
c_1 = -0.15;
c_2 = -3.2175;
a = app.ShapingfunctionvariableSlider.Value;
% Plot radial profile
plot(app.HorizontalAxes, r, compute_u(app, r, z, ur_max, u_trans, r_max, z_max, c_1, c_2, a, p), 'k', r, compute_ur(app, r, z, ur_max, u_trans, r_max, z_max, c_1, c_2, a, p), 'r', r, compute_uz(app, r, z, ur_max, r_max, z_max, c_1, c_2, a, p), 'b');
p = app.HorizontalAxes.Children;
p(1).LineWidth = 1.5;
p(2).LineWidth = 1.5;
p(3).LineWidth = 1.5;
legend(app.HorizontalAxes, 'Magnitude', 'Horizontal Velocity', 'Vertical Velocity');
legend(app.HorizontalAxes, 'Location', 'southoutside');
% Adjust axis for radial profile
r = 0:1:10000;
m = [compute_u(app, r, z, ur_max, u_trans, r_max, z_max, c_1, c_2, a, p)];
v_max = max(m, [], 'all');
v_lim = 1.1 * v_max;
r_lim = find(m<(v_lim+1) & m>(v_lim-1), 1, 'last');
xlim(app.HorizontalAxes, [0, (r_lim+500)]);
function u = compute_u(app, r, z, ur_max, u_trans, r_max, z_max, c_1, c_2, a, p)
% Horizontal downburst velocity
u_r = p .* ((ur_max .* r) ./ r_max) .* ((exp(c_1 * (z/z_max)) - exp(c_2 * (z/z_max))) / (exp(c_1) - exp(c_2))) .* (exp((1 - (((r.^2)/(r_max^2)).^a)) / (2*a))) + u_trans;
% Vertical downburst velocity
u_z = -2 * p .* ((ur_max * z_max) ./ r_max) .* (((1/c_1)*(exp(c_1 * (z/z_max)) - 1) - (1/c_2)*(exp(c_2 * (z/z_max)) - 1)) / (exp(c_1) - exp(c_2))) .* (1 - (0.5 * ((r.^2/r_max^2).^a))) .* (exp((1 - (((r.^2)/(r_max^2)).^a)) / (2*a)));
% Downburst velocity magnitude
u = sqrt(u_r.^2 + u_z.^2);
end
function u_r = compute_ur(app, r, z, ur_max, u_trans, r_max, z_max, c_1, c_2, a, p)
% Horizontal downburst velocity
u_r = p .* ((ur_max .* r) ./ r_max) .* ((exp(c_1 * (z/z_max)) - exp(c_2 * (z/z_max))) / (exp(c_1) - exp(c_2))) .* (exp((1 - (((r.^2)/(r_max^2)).^a)) / (2*a))) + u_trans;
end
function u_z = compute_uz(app, r, z, ur_max, r_max, z_max, c_1, c_2, a, p)
% Vertical downburst velocity
u_z = -2 * p .* ((ur_max * z_max) ./ r_max) .* (((1/c_1)*(exp(c_1 * (z/z_max)) - 1) - (1/c_2)*(exp(c_2 * (z/z_max)) - 1)) / (exp(c_1) - exp(c_2))) .* (1 - (0.5 * ((r.^2/r_max^2).^a))) .* (exp((1 - (((r.^2)/(r_max^2)).^a)) / (2*a)));
end
% Regular MATLAB testing code
% Define parameters for radial profile
t = 30;
for t_int = 15
if t <= t_int
p = t / t_int;
else
p = exp((-(t-t_int))/11.542);
end
end
disp(p)
class(p)
r = 0:0.1:10000;
z = 100;
r_max = 1000;
z_max = 100;
ur_max = 40;
u_trans = 10;
c_1 = -0.15;
c_2 = -3.2175;
a = 2;
plot(r, compute_u(r, z, ur_max, u_trans, r_max, z_max, c_1, c_2, a, p));
% Adjust axis for radial profile
r_v = 0:1:10000;
m = [compute_u(r_v, z, ur_max, u_trans, r_max, z_max, c_1, c_2, a, p)];
v_max = max(m, [], 'all');
v_lim = 1.1 * u_trans;
r_lim = find(m<(v_lim+1) & m>(v_lim-1), 1, 'last');
xlim([0, (r_lim+500)]);
function u = compute_u(r, z, ur_max, u_trans, r_max, z_max, c_1, c_2, a, p)
% Horizontal downburst velocity
u_r = p * ((ur_max .* r) ./ r_max) .* ((exp(c_1 * (z/z_max)) - exp(c_2 * (z/z_max))) / (exp(c_1) - exp(c_2))) .* (exp((1 - (((r.^2)/(r_max^2)).^a)) / (2*a))) + u_trans;
% Vertical downburst velocity
u_z = -2 * p * ((ur_max * z_max) ./ r_max) .* (((1/c_1)*(exp(c_1 * (z/z_max)) - 1) - (1/c_2)*(exp(c_2 * (z/z_max)) - 1)) / (exp(c_1) - exp(c_2))) .* (1 - (0.5 * ((r.^2/r_max^2).^a))) .* (exp((1 - (((r.^2)/(r_max^2)).^a)) / (2*a)));
% Downburst velocity magnitude
u = sqrt(u_r.^2 + u_z.^2);
end

채택된 답변

Stephen23
Stephen23 2023년 1월 30일
편집: Stephen23 2023년 1월 30일
The basic problem is that you have re-used the variable name p. You think that p is some value from the start of your code, but in fact you have re-used the name p for the content of the axes. These are the code lines in question:
if t <= t_int
p = t / t_int;
else
p = exp((-(t-t_int))/11.542);
end
..
p = app.HorizontalAxes.Children;
p(1).LineWidth = 1.5;
p(2).LineWidth = 1.5;
p(3).LineWidth = 1.5;
..
m = [compute_u(app, r, z, ur_max, u_trans, r_max, z_max, c_1, c_2, a, p)];
Inside COMPUTE_U you treat the last input argument as if it were numeric, which clearly it isn't any more. Note that those square brackets do absolutely nothing, you should get rid of them.
Tip for this forum: if you are getting an error messge please show us the complete error message. This means all of the red text.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Introduction to Installation and Licensing에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by