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

2 次查看(过去 30 天)
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