need help - matlab

edited March 2008 in Science & Tech
Hi I'm writing some code for a project that I'm doing, but I'm gettinga bit stuck with a plot function - well a part of it anyway, I want to may a plot that will draw a circle/circular function. Everytime I run the following code:

plot(R_sc_E(:,1),R_sc_E(:,2))
hold on
circle([0,0],R_earth,200,'g');
title('Position with Respect to Earth')
xlabel('km')
ylabel('km')
axis equal

It tells me that I have an undefined function of variable called 'circle', if I create an m file with a routine for creating a circle

ie
format compact % tightens loose format
format long e % makes numerical output in double precision
theta = linspace(0,2*pi,100); % create vector theta
x = cos(theta); % generate x-coordinate
y = sin(theta); % generate y-coordinate
plot(x,y); % plot circle
axis('equal'); % set equal scale on axes per pixel
title('Circle of unit radius') % put title
c=2*pi % prints out 2*pi value
disp('end circle.m') % prints out literal string.
% End Circle

it then tells me that I'm trying to run a script as a function, can anyone help.

Thanks

Comments

  • shwaipshwaip bluffin' with my muffin Icrontian
    edited March 2008
    matlab is telling you exactly what you need to know :).

    functions and scripts are two different types of .m files. The main difference is that a function can take arguments, and will keep all of its variables in a separate workspace, and a script cannot take explicit arguments, and shares the main workspace.

    by calling circle([0,0],R_earth,200,'g');, matlab is interpreting this as calling the circle function with those arguments, however, you've written circle.m as a script - it doesn't need any arguments to plot the earth circle.

    you'd either need to rewrite circle.m as a function, or to call it as if it's a script.
Sign In or Register to comment.