Trying to find the corresponding value of a matrix with an input?
1 次查看(过去 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;
0 个评论
采纳的回答
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 个评论
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!