Problem Related to plot

조회 수: 6 (최근 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