Ran script given to me. Error message: Function definitions are not permitted in this context.
Afficher commentaires plus anciens
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!
Réponses (2)
Fangjun Jiang
le 2 Déc 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
le 2 Déc 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!
Catégories
En savoir plus sur Get Started with MATLAB 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!