The function above cannot be permitted in the context!!! If it needs to create a function file to save it, how?

function ookd(g,f)
%For more information, visit: www.matpic.com
%Modulation OOK
% Example:
% ookd([1 1 0 1 0],2)
%Author: Diego Orlando Barragn Guerrero
%diegokillemall@yahoo.com
%Loja (ECUADOR)
%Long Live Heavy-Metal
%See also:
%http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=14328&objectType=FILE
if nargin > 2
error('Too many input arguments');
elseif nargin==1
f=1;
end
if f<1;
error('Frequency must be bigger than 1');
end
t=0:2*pi/99:2*pi;
cp=[];sp=[];
mod=[];mod1=[];bit=[];
for n=1:length(g);
if g(n)==0;
die=zeros(1,100); %Modulante
se=zeros(1,100); %Seal
else g(n)==1;
die=ones(1,100); %Modulante
se=ones(1,100); %Seal
end
c=sin(f*t);
cp=[cp die];
mod=[mod c];
bit=[bit se];
end
ook=cp.*mod;
subplot(2,1,1);plot(bit,'LineWidth',1.5);grid on;
title('Binary Signal');
axis([0 100*length(g) -2.5 2.5]);
subplot(2,1,2);plot(ook,'LineWidth',1.5);grid on;
title('OOK modulation');
axis([0 100*length(g) -2.5 2.5]);

 Réponse acceptée

At the command line command
edit ookd
In the edit box that comes up, paste in the code. Then use the file menu to Save the file.

9 commentaires

If I want do two different files (for example ookd.m and ooks.m), how do I call ookd.m into ooks.m?
In ooks.m you would add a line that looked similar to
ookd([1 1 0 1 0],2)
I am not sure what the numbers are intended to mean though.
I had use the example of ookd([1 1 0 1 0],2), but it shows this error. I had no idea how to solve this even though I had try to use the set function.
Maximum recursion limit of 500 reached. Use set(0,'RecursionLimit',N)
to change the limit. Be aware that exceeding your available stack space can
crash MATLAB and/or your computer.
You cannot call ookd within a file named ookd.m . You had said that the function was to be called within ooks.m
The code for the file named ookd.m is shown as below:
function ookd(g,f)
if nargin > 2
error('Too many input arguments');
elseif nargin==1
f=1;
end
if f<1;
error('Frequency must be bigger than 1');
end
The MATLAB shows :
The input arguement "f" is undefined.
Error in ==> abc at 17
if f<1;
If I put the ookd([1 1 0 1 0],2) within that file, the maximum recursion limit problem occurs.
Do not put the
ookd([1 1 0 1 0],2)
inside ookd.m . Just put
ookd([1 1 0 1 0],2)
at the commmand line (or in a different file such as the ooks.m that you mentioned.)
The error showns:
The input arguement "f" is undefined.
Error in ==> abc at 17
if f<1;
In order to not be confused, all the codes combine into one file named as ookd.m. When I run the codes above, where should I include the
ookd([1 1 0 1 0],2)
If the code must be combined into a single file named ookd.m then put both of the following functions into ookd.m :
function ookd
ookd_internal([1 1 0 1 0],2);
function ookd_internal(g,f)
if nargin > 2
error('Too many input arguments');
elseif nargin==1
f=1;
end
if f<1;
error('Frequency must be bigger than 1');
end

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by