MATLAB Answers

Translated by

このページのコンテンツは英語から自動翻訳されています。自動翻訳をオフにする場合は「<a class="turn_off_mt" href="#" onclick="window._kiq.push(['set', { 'event': 'Turn off MT' }]);">ここ</a>」をクリックしてください。

0

Save each vector (of different length) produced by a for loop

Olivia Booth-Howe さんによって質問されました 2019 年 6 月 17 日 15:01
最新アクティビティ Star Strider
さんによって コメントされました 2019 年 6 月 18 日 17:14
Hello everyone,
Thanks for reading my question.
I have a for loop that generates a vector "H" that is a different size every time the loop runs. I am trying to save "H" with a different name every time in order to find the smallest "H" produced by the loop and eventually interpolate all the data onto the grid of the shortest "H" vector.
This is my code
B1=B(:,1);
B2=B(:,2);
figure(FileCounter)
for m=B1(1:end,:)
for n = B2(1:end,:)
for p=1:length(B1)
H=find(time_dec > m(p) & time_dec < n(p));
B1 and B2 mark the start and stop times (around 3-5, differing each time) that I am cutting H from. Therefore, I make 3-5 different H vectors every time that mark different time slices from a massive data set, because I am only looking at variables within those time frames. I can clarify any of this if that helps.
Does anyone know how I can save a new vector every time I create an H vector? Thank you so much!!!

  0 件のコメント

サインイン to comment.

タグ

1 件の回答

回答者: Star Strider
2019 年 6 月 17 日 15:11
 採用された回答

I’m not certain what you’re doing.
I would do something like this:
H{m(p),n(p)} = find(time_dec > m(p) & time_dec < n(p));
That creates a cell array, and cell arrays can have anything in them, most significantly here, different sized vectors in the cell array elements. The problem is to find a way of referring to the cell array elements so you can access them easily in the context of what you want to do with them. I chose referring to them in terms of the elements you are comparing. You obviously have the final say on the best approach.

  2 件のコメント

Thank you!
Star Strider
2019 年 6 月 18 日 17:14
As always, my pleasure!

サインイン to comment.



Translated by