Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Whats wrong with this matlab code?

  1. Feb 22, 2007 #1


    User Avatar
    Gold Member

    I have a very simply matlab code. When I try go run it, I get no graph and switching over to the matlab command line, I see:
    ans =


    Here is the code:
    Code (Text):

    t = linspace(0,60);
    v = 3.22;

    for q_0 = [0:1:2007];
        q = q_0*exp(v*t);
        hold on
    It looks just fine to me.

    Any feedback would be great.
  2. jcsd
  3. Feb 22, 2007 #2


    User Avatar
    Staff Emeritus
    Science Advisor
    Gold Member

    It runs fine in MATLAB R2006b on my computer.

    Perhaps try removing the semicolon at the end of "for q_0 = [0:1:2007];"

    - Warren
  4. Feb 22, 2007 #3


    User Avatar
    Gold Member

    I still get no luck. I can run other m-files from the same directory with no problems. Does it say anything on the matlab command line when you run it?
  5. Feb 22, 2007 #4
    I have copied-and-pasted the script on the Matlab (R11.1) command prompt and a figure appears. Nothing appears in the command line though.

    How did you try to run the script?
  6. Feb 22, 2007 #5

    Dr Transport

    User Avatar
    Science Advisor
    Gold Member

    It looks to me to be plotting every point in a separate graph,, try writing to an array and plot after the loop is complete. I;ll try at work tommorow where I have Matlab R2006B.
  7. Feb 22, 2007 #6


    User Avatar
    Gold Member

    I tried to run it from the m-file editor screen. The usual Debug>Run. I also even tried to get it from the command line, but I still get ans = char as an output.

    I dont think its separate graphs. Its done on one graph but the "hold on" command allows me to plot different values for q_0 on the same graph.

    Its is possible for anyone to post a screenshot of the graph? btw, I'm using R14.
  8. Feb 23, 2007 #7
    Here's a screenshot...

    Attached Files:

    • 01.jpg
      File size:
      34 KB
  9. Feb 23, 2007 #8


    User Avatar
    Gold Member

    Thanks doodle. It seems I have to do a little tweaking of my domain, but its what I expected it to be.
  10. Mar 7, 2007 #9


    User Avatar
    Gold Member

    It turns out I was getting this error becuase the name of the M-file had a white space. Beats me...
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook