フィルターのクリア

How to find a value that is close to the gap?

2 ビュー (過去 30 日間)
Ming Ki Lee
Ming Ki Lee 2017 年 1 月 25 日
回答済み: Walter Roberson 2017 年 1 月 25 日
L=50;
dx=5;
Xp = L/dx;
Xs=8
start=0;
eend=dx;
for n=1:Xp
if Xs>=start && Xs<=eend
start = eend;
else
eend = eend*n;
end
end
n= 0 1 2 3 4 5 6 7 8 9 10
The problem is there are 50/5=25 gaps, from 0 5 10 15 20 25 30 35 40 45 50, and I want to find the one that is near Xs. From the above, Xs=8 so it is closer to 10. I want to find the number of n. What went wrong with my code?

回答 (1 件)

Walter Roberson
Walter Roberson 2017 年 1 月 25 日
t = start : dx : L;
n = 0:length(t)-1;
n_val = interp1( t, n, Xs, 'nearest');
Cross-check:
t(n_val == n)

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by