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

1 visualizzazione (ultimi 30 giorni)
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;

Risposta accettata

Karim
Karim il 7 Lug 2022
Modificato: Karim il 7 Lug 2022
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

Più risposte (0)

Categorie

Scopri di più su Interpolation in Help Center e File Exchange

Prodotti


Release

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by