Why does this keep giving me the error "Not enough input arguments"

I'm a beginner at MatLab so sorry for asking this very 'noobish' question. I'm basically trying to plot the following function, f(x) = cos(x) * sin(x)
In my "main" matlab file, I have the following code:
x = 0:pi/1000:2*pi;
third = ThirdFunction(x);
plot(x,third,'y');
axis([0 2*pi -3 3])
xlabel('X - Axis')
ylabel('Y - Axis')
title('Sinusodial Graph')
This is the code for my ThirdFunction
function [y] = ThirdFunction(x)
%FIRSTFUNCTION Summary of this function goes here
% Used to graph the first function
y = tan(x) * sin(x);
end
Everytime I try to compile, it gives me the following error: 'Error using ThirdFunction (line 4) Not enough input arguments."
Thanks in advance :)

2 Kommentare

I ran it in a nested function and it ran without error once I used element-wise multiplication here:
y = tan(x) .* sin(x);
What specifically is ‘line 4’?
Do you really want to plot in yellow by the way?! You'll hardly see it on a white background!

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

Adam
Adam am 27 Sep. 2014
You seem to be using tan(x) rather than cos(x).
Also you need to use .* rather than * i.e.
y = cos(x) .* sin(x);
I wouldn't think either of those would result in a not enough input arguments error though.

2 Kommentare

Thanks so much, it was because I didn't use .* The operator simply means multiplication right?
.* means simply point-wise multiplication of two matrices/vectors of equal size. * is matrix multiplication so subject to the rules of that which I always manage to forget what they are!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Surfaces, Volumes, and Polygons finden Sie in Hilfe-Center und File Exchange

Tags

Noch keine Tags eingegeben.

Gefragt:

am 27 Sep. 2014

Kommentiert:

am 27 Sep. 2014

Community Treasure Hunt

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

Start Hunting!

Translated by