Finding the index of x values to create an equally spaced array.

92 ビュー (過去 30 日間)
HenT2020
HenT2020 2020 年 4 月 4 日
コメント済み: Star Strider 2020 年 4 月 5 日
Hi,
I would like to pick 53 (or any other arbituary number) data points from my data set by selecting the index of the matrix.
I would like to know the y values of 53 evenly spaced values of x. I want to plot the same graph but with only 53 data points. Ive attempted this by creating a linspace of length 53 with max and min values corresponding to the data, then trying to use the 'find' function for when my x array is equal to these numbers to find the array indices, and then finally finding the corresponding y-values.
dx = linspace(minx,maxx,53);
inx = find(x == dx);
dy = y(inx);
what I find very confusing is that the inx indexes are much larger than the size of the x and y arrays ( a factor of about 80 for some reason) so I cant find the corresponding y values as it exceeds the array.
Any help would be much apprieciated, cheers
  1 件のコメント
Florian Floh
Florian Floh 2020 年 4 月 4 日
Hi,
are your x-values equally spaced or randomly sampled?

サインインしてコメントする。

採用された回答

Star Strider
Star Strider 2020 年 4 月 4 日
Your approach appears to be correct, as far as it goes. Use the interp1 function to create your result vector:
x = 0:195;
y = 8*exp(-0.03*x) + 2;
dx = linspace(min(x),max(x),53);
dy = interp1(x, y, dx);;
figure
plot(x, y, '-b')
hold on
plot(dx, dy, '+r')
hold off
  2 件のコメント
HenT2020
HenT2020 2020 年 4 月 5 日
Thanks! This solves my problem
Star Strider
Star Strider 2020 年 4 月 5 日
As always, my pleasure!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

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

タグ

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by