Hey there! Sign in to join this conversationNew here? Join for free
x Turn on thread page Beta
    • Thread Starter
    Offline

    2
    ReputationRep:
    We have this sheet thing to work through and it tells me to:

    (i) In the MATLAB Command Window menu, click on File.
    (ii)Click New then M-file.
    (iii) Within Notepad which you have now started, you can type some lines, for example
    %myfile.m
    %It doesn't do much, just identifies itself.
    %These 3 lines are comment lines which MATLAB ignores.
    disp('I am an M-file')
    (iv) Clcik File then Save As.
    (v) Within the box File Name which is open waiting, type in myfile.m.
    (vi) Click OK.

    You have now created a file which MATLAB can find and use. You hope!

    Back in the MATLAB Command Window you can now ask MATLAB whther it can find the file. Type

    >> type myfile

    and you should see a list of the lines which you typed in.
    This works, I think. When I type myfile, MATLAB gives me

    %myfile.m
    %It doesn't do very much, just identifies itself.
    %These 3 lines are comment lines which MATLAB ignores.
    disp('I am an M-file')
    However it then goes on to say:
    If all is well, you now have your first example of a script file. To use it you simply type

    >> myfile

    whereupon you should see something like

    I am an M-file
    This doesn't happen. Instead upon typing "myfile" I get

    ??? Undefined function or variable 'myfile'.
    Help!
    Offline

    0
    ReputationRep:
    (Original post by Hathlan)
    We have this sheet thing to work through and it tells me to:



    This works, I think. When I type myfile, MATLAB gives me



    However it then goes on to say:


    This doesn't happen. Instead upon typing "myfile" I get



    Help!
    Try right clicking the m-file in the command window instead and select run instead
    • Thread Starter
    Offline

    2
    ReputationRep:
    (Original post by Necro Defain)
    Try right clicking the m-file in the command window instead and select run instead
    Upon your reply I tried this, but to no avail; again it gives me

    ??? Undefined function or variable 'myfile'.
    Offline

    1
    ReputationRep:
    Check your working directory is the same as where u saved your m-file. And open the m-file within matlab.
    Offline

    15
    ReputationRep:
    or type

    run myfile

    (edit: yes check that it's in the working directory (though I assume it is if "type myfile" works))
    Offline

    0
    ReputationRep:
    In the main command window, there should be a smaller window called 'current directory'. Make sure this is set to the folder in which you have saved your m file.

    Matlab can do this for you almost automatically if you go to the script editor where you wrote your file, and run it from there. You will then be asked if you want to change directories - say yes.
    • Thread Starter
    Offline

    2
    ReputationRep:
    (Original post by Phugoid)
    ...
    (Original post by llys)
    ...
    (Original post by whiplash)
    ...
    This is why I told you that "type myfile" works. Twas the first thing I checked, after a quick pre-tsr google (I don't want to look too ridiculous on tsr!), and could quite reasonably have been the error. But alas "myfile.m" is and always has been (since the dinosaurs) located in the "Current Directory".
    • Community Assistant
    • Study Helper
    Offline

    20
    ReputationRep:
    Community Assistant
    Study Helper
    I'm as confused as you as to what the problem is. Can you post a screenshot of your MATLAB screen when you get the error?
    • Thread Starter
    Offline

    2
    ReputationRep:
    I did the age olf close-it-down-start-it-up-again and now it works. Thanks for trying, everyone. Still don't really understand what the problem was. :iiam:
    Offline

    15
    ReputationRep:
    I know what the problem was. Are you on a network? If so you sometimes have to type

    rehash path

    to make things work again. (Don't ask me why. :iiam: )
 
 
 
Reply
Submit reply
Turn on thread page Beta
Updated: January 18, 2010
Poll
Do you agree with the proposed ban on plastic straws and cotton buds?
Useful resources

Make your revision easier

Maths

Maths Forum posting guidelines

Not sure where to post? Read the updated guidelines here

Equations

How to use LaTex

Writing equations the easy way

Student revising

Study habits of A* students

Top tips from students who have already aced their exams

Study Planner

Create your own Study Planner

Never miss a deadline again

Polling station sign

Thinking about a maths degree?

Chat with other maths applicants

Can you help? Study help unanswered threads

Groups associated with this forum:

View associated groups

The Student Room, Get Revising and Marked by Teachers are trading names of The Student Room Group Ltd.

Register Number: 04666380 (England and Wales), VAT No. 806 8067 22 Registered Office: International House, Queens Road, Brighton, BN1 3XE

Write a reply...
Reply
Hide
Reputation gems: You get these gems as you gain rep from other members for making good contributions and giving helpful advice.