It is possible to read the graph and it has to produce the Y value for my input X value.
2 views (last 30 days)
Show older comments
Vivek on 3 Jan 2013
This is what my program to create a graph.. now i want to read the graph and it has to produce the y value for my input x value. is there any syntax for that?
j=input('Enter the number of straight lines in the graph: ');
disp('Enter the X Y co-ordinate of one end of the straight line:');
disp('Enter the X Y co-ordinate of another of the straight line:');
c(i)=input('Enter the Y-intercept for straight line: ');
%axis([-10 10 -5 5])
disp('your graph is displayed');
disp('Enter the X value from your graph: ');
disp('Corresponding Y is: ');
Davide Ferraro on 3 Jan 2013
Why are you asking two (x,y) values for a line and then also the intercept? Given two points you are able to calculate both m and c. And that point you will have the equation y of your line that you can evaluate to find the corresponding Y.
If you have more lines you may consider including and IF-ELSE statement, check what is the X value, associate it to the corresponding equation and then evaluate the equation. As Walter pointed out you may have multiple Y values, you may prevent this by checking that the user is using different X ranges when creating the curves.
More Answers (1)
Dr. Seis on 3 Jan 2013
Edited: Dr. Seis on 3 Jan 2013
Disregarding the fact that you can determine your c value from your m value, x1 value, and y1 value (or m, x2 and y2)... I think the syntax you are looking for (following your current syntax) is something like:
new_y = ... ; % Determine new y value for input x value
disp(sprintf('Corresponding Y is: %f',new_y));
Find more on 2-D and 3-D Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!