Incorrect number of input arguments when plotting in the main script getting data from a nested function

30 visualizzazioni (ultimi 30 giorni)
Hi,
My main script is :
dx=0.01;
t=0.1;
for i=1:101
xx(i)=(i-1)*dx;
end
......
......
for i=1:21
yy(i)=(i-1)*dx
end
for i = 2:100
t=0.1
if xx(i) < t
differentiation1(i) = (p2(i) - p2(i-1))./dx
else
differentiation1(i) = (p2(i+1) - p2(i))./dx
end
end
[p2_small,p2_small_small,Momentum_x1big,dp2dx] = small_time()
figure()
plot(xx(2:21),differentiation1(2:21), 'LineWidth', 2);
hold on
plot(xx(2:21),dp2dx(2:21),'LineWidth',2)
xlabel('x')
ylabel('dp2/dx from the pde code')
legend('dp_2/dx from x<t','d^2p_2/dx^2 from x>t')
title(['Pressure_2 derivative from general pde solution in time= ',num2str((nt-1)/(10000)),',alphabar=',num2str(alpha)])
And the nested function :
......
yy= zeros(1,21);
for i=1:21
t = 0.1
yy(i)=(i-1)*dx
if yy(i) < t
dp2dx(i) = -beta1-3*beta1^2.*yy(i)
else
dp2dx(i) = -beta1+2.*yy(i)*(-beta1*alphabar-1.5*beta1^2)+t*2*beta1*alphabar
end
end
figure(..)
plot(yy(2:end),dp2dx(2:end),'LineWidth',2)
xlabel('x');
ylabel('dp2/dx from analytical solution in 0 <x1< 1 and 1 <x1< 2 in time =',num2str(nt-1/1000)')
If I plot the nested function, it is fine.
If I plot just differentiation in a figure, again it is fine.
If I combine these plots as above in the main script it says:
Error using ylabel (line 27) Incorrect number of input arguments* and complaints the ylabel of the plot line in the nested function

Risposta accettata

Star Strider
Star Strider il 9 Mag 2015
I believe I see the problem — it’s not the title (because I don’t see a title call, but in your last ylabel call.
See if substituting this for it helps:
ylabel(sprintf('dp2/dx from analytical solution in 0 <x1< 1 and 1 <x1< 2 in time = %f', (nt-1/1000)))
  7 Commenti
Star Strider
Star Strider il 9 Mag 2015
@Walter — Thank you.
@Meva — I don’t see the problem. The title call you just now posted runs for me without error (with random ‘nt’ and ‘alpha’).
I would nevertheless replace it with the more efficient sprintf call:
title(sprintf('Pressure_2 derivative from general pde solution in time = %f, alphabar = %f',(nt-1)/(10000),alpha))

Accedi per commentare.

Più risposte (1)

Banu priya.M
Banu priya.M il 19 Nov 2020
I am getting warning as incorrect number of input arguments...help me
gridSize = 6;
mu = linspace(100, 150, gridSize);
nu = linspace(0.5, 2, gridSize);
[M,N] = meshgrid(mu, nu);
Z = nan(size(N));
c = surf(M, N, Z);
xlabel('\mu Values','Interpreter','Tex')
ylabel('\nu Values','Interpreter','Tex')
zlabel('Mean Period of y')
view(137, 30)
axis([100 150 0.5 2 0 500]);
D = parallel.pool.DataQueue;
D.afterEach(@(x) updateSurface(c,xlabel));
parfor ii = 1:numel(N)
[t, y] = solveVdp(M(ii), N(ii));
l = islocalmax(y(: , 2));
send(D, [ii mean(diff(t(l)))]);
end
function [t, y] = solveVdp(mu, nu)
f = @(~,y) [nu*y(2); mu*(1-y(1)^2)*y(2)-y(1)];
[t,y] = ode23s(f,[0 20*mu],[2; 0]);
end
function updateSurface(s, d)
s.ZData(d(1)) = d(2);
drawnow('limitrate');
end

Community Treasure Hunt

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

Start Hunting!

Translated by