Finding corresponding values in data set
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
jrz
am 16 Sep. 2022
Kommentiert: Star Strider
am 16 Sep. 2022
I have a set of matrices each with 4 columns. I want to extract the value of the 1st column corresponding to the 0 in the second column and plot that point. How can I do this? and for cases where there is no exact zero, interpolate between the two values that cross 0?
2 Kommentare
Walter Roberson
am 16 Sep. 2022
Is there always exactly one 0 or zero crossing, or could there be several?
are the values in that column sorted?
Akzeptierte Antwort
Star Strider
am 16 Sep. 2022
Bearbeitet: Star Strider
am 16 Sep. 2022
I would just do the interpolation using interp1 since it will interpolate to 0 or the closest value to it.
Try this —
M = randn(10,4)
L = size(M,1);
idx = find(diff(sign(M(:,2))))
for k = 1:numel(idx)
idxrng = max(1,idx(k)-1) : min(L,idx(k)+1);
Result(k,:) = interp1(M(idxrng,2), M(idxrng,:),0);
end
Result
EDIT — Aesthetic tweaks.
.
4 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Interpolation 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!