taking samples from a vector

34 ビュー (過去 30 日間)
Paul Rogers
Paul Rogers 2020 年 9 月 21 日
コメント済み: Star Strider 2020 年 9 月 21 日
I have the vector psi. It has too many items and I cannot copy and paste the values in a txt file to plot a graph in Latex.
Would be great to have a small code to take a sample like every 5 or 10 items to reduce the size and create a new file psi_short.
It won't lose the shape since its dicretization is very high.
I wrote this but it doesn change anithyng:
for i=1:length(psi)
psi_short(i) =psi(i);
i=i+5;
end
  1 件のコメント
Star Strider
Star Strider 2020 年 9 月 21 日
Use my code.
It is not possible to change the index in a for loop. The for function simply ignores the changes (although you can use changed values for it in calculations).
Even if it worked, the explicit loop is much less efficient than the indexing approach my code uses.

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

採用された回答

Star Strider
Star Strider 2020 年 9 月 21 日
Try these:
D = load('psi.mat');
psi = D.psi; % (10962 x 1)
Every5 = psi(1:5:end); % (2193 x 1)
Every10 = psi(1:10:end); % (1097 x 1)
.
  4 件のコメント
Paul Rogers
Paul Rogers 2020 年 9 月 21 日
Thanks again a lot. I was making such a stupid mistake after a long day in front of the laptop.
Have a great day and thank yoou again.
Star Strider
Star Strider 2020 年 9 月 21 日
Thank you!
As always, my pleasure!
I don’t consider mistakes stupid if their solution is instructive!

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

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2014b

Community Treasure Hunt

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

Start Hunting!

Translated by