Whats wrong with this matlab code?

  • MATLAB
  • Thread starter ranger
  • Start date
  • #1
ranger
Gold Member
1,676
1

Main Question or Discussion Point

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 =

char

Here is the code:
Code:
t = linspace(0,60);
v = 3.22;

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

Any feedback would be great.
 

Answers and Replies

  • #2
chroot
Staff Emeritus
Science Advisor
Gold Member
10,226
34
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
 
  • #3
ranger
Gold Member
1,676
1
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?
 
  • #4
161
0
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?
 
  • #5
Dr Transport
Science Advisor
Gold Member
2,329
445
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.
 
  • #6
ranger
Gold Member
1,676
1
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?
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.

Dr Transport said:
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.
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.
 
  • #7
161
0
Its is possible for anyone to post a screenshot of the graph? btw, I'm using R14.
Here's a screenshot...
 

Attachments

  • #8
ranger
Gold Member
1,676
1
Thanks doodle. It seems I have to do a little tweaking of my domain, but its what I expected it to be.
 
  • #9
ranger
Gold Member
1,676
1
It turns out I was getting this error becuase the name of the M-file had a white space. Beats me...
 

Related Threads on Whats wrong with this matlab code?

Replies
1
Views
1K
Replies
2
Views
3K
Replies
1
Views
2K
  • Last Post
Replies
4
Views
571
  • Last Post
Replies
1
Views
1K
Replies
7
Views
789
Replies
11
Views
2K
Replies
2
Views
25K
Replies
3
Views
2K
Top