Reputation: 31
this is my program, its supposed to get an input from the user for the starting x value, stepping value, and an ending x value, the user also inputs the y function he likes, the graph is then supposed to graph it but i keep getting an error, any ideas?
clear all ; % clear memory
close all ; % close any open figures
drawnow ; % update screen now
clc ; % clear screen
display('** Welcome to Plotting Program **') ;
display(' ');
start=input('please enter starting x value:');
step=input('please enter ending x value:');
stop=input('please enter step value:');
y= double(input('please input your equation:'));
x=double(start:step:stop);
plot(x,y);
Upvotes: 0
Views: 34
Reputation: 10676
You can use str2func() to convert string input into a function handle:
y = input('Input only the RHS of your equation as a function of ''x'' and enclose in '': ')
y = str2func(['@(x)' y]);
plot(x,y(x))
Also note that double(start:step:stop)
will not work, since you are converting chars to their ASCII mapping:
double('20')
ans =
50 48
Use instead str2double(input('...'))
Upvotes: 1