Reputation: 413
I use the MATLAB built-in ezplot
to draw the graph of a parametric equation. For instance,
ezplot('sin(t)+2*cos(t)','3*sin(t)+cos(t)',[0,2*pi])
Now, I replace this expression with the following code:
a=1;
b=2;
c=3;
ezplot('a*sin(t)+b*cos(t)','c*sin(t)+cos(t)',[0,2*pi])
I don't kown how to deal with this case?
Upvotes: 3
Views: 209
Reputation: 36720
Instead of passing strings, pass a function handle. In this case a,b and c will be evaluated:
a=1;
b=2;
c=3;
ezplot(@(t)a*sin(t)+b*cos(t),@(t)c*sin(t)+cos(t),[0,2*pi])
Upvotes: 4
Reputation: 35525
that is because MATLAB does not now that the 'a'
in the string you defined is the variable called a
.
My recommendation: if you want to go changing the equations, change it using string replacement tenciques, or string concatenation techniques.
e.g. ezplot([num2str(a), '+', num2str(b),'*cos(t)'],......)
Upvotes: 5