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

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

 Réponse acceptée

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 commentaires

nope, unfortunately, that wasnt the problem.
It gives an error in the title since it complains about the plot.
I don’t understand your reference to title. I do not see a title call in the code you posted.
You need to post the exact line that’s throwing the error, then, since I don’t see it.
The error you posted in your Question says ylabel and line 27. Your original ylabel call in the second figure throws the same error when I run it, whereas my corrected one does not. (The first ylabel call looks correct to me.)
sorry you are right. I deleted because of avoiding from confusion. I have edited my question. We can see the title in the main program
I agree, the original call
ylabel('dp2/dx from analytical solution in 0 <x1< 1 and 1 <x1< 2 in time =',num2str(nt-1/1000)')
is incorrect, as it attempts to use two arguments to ylabel.
An alternate fix would be
ylabel(['dp2/dx from analytical solution in 0 <x1< 1 and 1 <x1< 2 in time =',num2str(nt-1/1000)'])
yes your solution solved my problem. Thanks.
@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))

Connectez-vous pour commenter.

Plus de réponses (1)

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

2 commentaires

I think you have a typo. Replace
D.afterEach(@(x) updateSurface(c,xlabel));
with
D.afterEach(@(x) updateSurface(c,x))

Connectez-vous pour commenter.

Catégories

En savoir plus sur Startup and Shutdown dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by