Saving Data for for loop into a vector

1 回表示 (過去 30 日間)
Brian Bowne
Brian Bowne 2021 年 4 月 8 日
回答済み: Star Strider 2021 年 4 月 8 日
I have a vector of 1801 THRUST data points. I am determining when the THRUST data is less than 0.43 and trying to index at what points this is the case. I am then trying to find the corresponding times. I have another vector, TIME, of the same length. Below is my code, but I cannot get it to print out the indexed times as a vector. Any help is appreciated
for i = 1:1801
if find(THRUST > 0.43)
Y(x) = TIME(i)
end
else Y = NaN
end
end

回答 (1 件)

Star Strider
Star Strider 2021 年 4 月 8 日
The loop is likely not necessary.
Try this:
idx = find(THRUST>=0.43, 1, 'first');
Time = TIME(idx);
to get the closest index, or:
idx = find(THRUST>=0.43, 1, 'first');
Time = interp1(THRUST(idx-2:idx), TIME(idx-2:idx), 0.43);
to interpolate to a more precise value, if ‘THRUST’ is never exactly 0.43.

カテゴリ

Help Center および File ExchangeInterpolation についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by