Problem Related to plot
2 views (last 30 days)
Show older comments
I am plotting a graph, say X vs Y. What command is to be used in order to extract values of Y with respect to Different values of X.? Say, X ranges from 0 to 20 and Y ranges from 0 to 10. The plot is of non-linear nature. I want values of Y for different X such as 10,15 and 23. So what command is to be used to find values of Y?
0 Comments
Answers (1)
Akshat
on 30 Jan 2025
In order to get values of Y for different X can be found using the function "interp1".
As you have said, you need values of Y when X is 10,15 and 23. Here, 23 is out of the range of X as you originally specified it will from 0 to 20.
For such values, "interp1" will give NaN values. You can understand more about "interp1" from the following official MathWorks documentation:
Here is some boilerplate code for using the function:
X = linspace(0, 20, 100); % Example X data
Y = sin(X); % Example Y data (non-linear relationship)
X_query = [10, 15, 23];
Y_query = interp1(X, Y, X_query);
disp(table(X_query', Y_query', 'VariableNames', {'X', 'Y'}));
Hope this helps!
0 Comments
See Also
Categories
Find more on Annotations 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!