How to extract y-value data at a certain x-value?
8 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
aman verma
am 14 Jun. 2022
Kommentiert: Star Strider
am 14 Jun. 2022
I would like to take all the y values from the attached figure that incercept the x data value of 5x10^5 Hz and then re-create this figure but instead Velocity against Resonator length. Is there a way to do this?
thank you
Akzeptierte Antwort
Star Strider
am 14 Jun. 2022
The code is incomplete and cannot run as posted.
Using the .fig file instead:
F = openfig('Velocity against frequency for changing resonator length.fig');
Ax = gca(F);
Lm = findobj(Ax, 'Type','line');
Xq = 5E+5;
for k = 1:numel(Lm)
Xv{k,:} = Lm(k).XData;
Yv{k,:} = Lm(k).YData;
Zv{k,:} = Lm(k).ZData;
if numel(unique(Xv{k})) > 1
Yq(k,:) = interp1(Xv{k},Yv{k}, Xq)
else
Yq(k,:) = NaN;
end
end
figure
plot(1:numel(Yq), Yq, 'x')
grid
xlabel('Arbitrary Vector')
ylabel('Velocity')
produces:

Here, ‘Xq’ is the desired frequency of
Hz and ‘Yq’ are the interpolated values that intercept that value. Since ‘Resonator Length’ is nowhere defined in the code, I plotted it against the index vectors of ‘Yq’. If ‘ResonatorLength’ is defined, it should be assigned within the if block under both conditions, so that it can be plotted as the independent variable in the figure plotted in my code, for example:

if numel(unique(Xv{k})) > 1
RL(k,:) = "Resonator Length At This Value Of The Existing Data";
Yq(k,:) = interp1(Xv{k},Yv{k}, Xq)
else
RL(k,:) = "Resonator Length At This Value Of The Existing Data";
Yq(k,:) = NaN;
end
and then plot ‘Yq’ against ‘RL’ instead of against ‘Arbitrary Vector’.
.
2 Kommentare
Star Strider
am 14 Jun. 2022
I cannot run the code, so I cannot figure out how ‘x’ is used in it, or with respect to the plot. There does not appear to me to be any specific relation between ‘x’ (or ‘l’) and whatever is being plotted.
So, I am going with this option:
RL = linspace(0.001,0.01,numel(Yq));
figure
plot(RL, Yq, 'x')
grid
xlabel('Resonator Length')
ylabel('Velocity')
producing this plot:

That is the best I can do.
.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu 2-D and 3-D Plots finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!