Ran script given to me. Error message: Function definitions are not permitted in this context.
Ältere Kommentare anzeigen
These were the directions: For use in the next few problems, we will need the mle simpvec. So write the following script and save it as simpvec.m.
This is the script that I put into matlab:
>> function s=simpvec(n)
s=2*ones(1,n+1);
s(2:2:n)=4*ones(1,n/2);
s(1)=1; s(n+1)=1
??? function s=simpvec(n)
|
Error: Function definitions are not permitted in this context.
Please help!
Antworten (2)
Fangjun Jiang
am 2 Dez. 2011
You need to save your code into a file called simpvec.m
function s=simpvec(n)
s=2*ones(1,n+1);
s(2:2:n)=4*ones(1,n/2);
s(1)=1; s(n+1)=1
Then run it in the Command Window, for example
s=simpvec(5)
Sean de Wolski
am 2 Dez. 2011
You're trying to define the function simpvec at the command line (at least that's what it looks like). This isn't allowed. The function has tro be in its own file.
At the command line run:
edit simpvec
It'll prompt you to open a new editor window. Copy and paste what you have above and save it. Then call:
n = pi; %or whatever it is
s = simpvec(n);
at the command line.
doc function
for more info. Good Luck!
Kategorien
Mehr zu Get Started with MATLAB finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!