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

66 views (last 30 days)
Meva on 9 May 2015
Commented: Star Strider on 9 May 2015
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

Star Strider on 9 May 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)))

Meva on 9 May 2015
yes your solution solved my problem. Thanks.
Star Strider on 9 May 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))
Star Strider on 9 May 2015
@Meva — My pleasure!