Problem Related to plot

8 次查看(过去 30 天)
Purva Nagvekar
Purva Nagvekar 2019-1-21
回答: Akshat 2025-1-30
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?

回答(1 个)

Akshat
Akshat 2025-1-30
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!

类别

Help CenterFile Exchange 中查找有关 Annotations 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by