Trying to find the corresponding value of a matrix with an input?

조회 수: 1 (최근 30일)
rman
rman 2022년 7월 7일
편집: Karim 2022년 7월 7일
I have a Matrix of values (A). In the first column, it conttains the length of the rods and in the second column it contains the velocity. I want to find a script / code that allows me to input a velocity value and then find the corresponding rod height.
However, one issue is that the velocity values are not exact numbers. For example, one velocity value is 2.8757e3 . Therefore, I would need the script to interpolate the input value and find the interpolated rod height. But I have an array of velocity value that i need to find the corresponding rod heights for. Is there a way to do this?
I will attach my code and my figures.
%% height(x,y)
% Calculate the height here --> fig 1(e)
% Interpolate the velocity with the rod height
fig = openfig('VelocityAgainstRodHeight500Hz.fig');
axObjs = fig.Children;
dataObjs = axObjs.Children;
rod_heights = dataObjs(1).XData;
velocities = dataObjs(1).YData;
A = [];
A(:,1)=rod_heights;
A(:,2)=velocities;

채택된 답변

Karim
Karim 2022년 7월 7일
편집: Karim 2022년 7월 7일
see below for the interpolation
fig = openfig('VelocityAgainstRodHeight500Hz.fig');
axObjs = fig.Children;
dataObjs = axObjs.Children;
rod_heights = dataObjs(1).XData;
velocities = dataObjs(1).YData;
% generate some random velocity values between 750 and 2750
NewVelocities = rand(15,1)*2000 + 750;
% evaluate the rod heigt via interpolation
NewRodHeights = interp1(velocities,rod_heights,NewVelocities,'linear');
% plot the new points
hold on
scatter(NewRodHeights,NewVelocities,'r','filled')
hold off

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Interpolation에 대해 자세히 알아보기

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by