Filling in multidimensional array efficiently

5 ビュー (過去 30 日間)
Haneen
Haneen 2020 年 12 月 23 日
回答済み: James Tursa 2020 年 12 月 23 日
I need to fill in array of the size (900,1800,80,60) --> (tr,t,f,ch) through a for loop. In every iteration, I will get a bunch of data for a particular f and ch. This bunch, call it b, is the size of 50 by1800 and sometimes it is 49 by 1800.
Example:
array(?,:,f_1,ch_1) = b
I wish in each loop to fill in bunch b in my array. Is there an easy way to determine "?" in each loop? Alternatively, is there an easier way to fill in "array"?

採用された回答

Matt J
Matt J 2020 年 12 月 23 日
If you want b to be inserted in the topmost rows of each array(:,:,f, ch), then it would be,
array(1:size(b,1),:,f, ch) = b
  2 件のコメント
Haneen
Haneen 2020 年 12 月 23 日
This looks good, the problem is that in the next iteration, the new b will erase the old b. I would like the "b's" to be inserted on top of each other
Matt J
Matt J 2020 年 12 月 23 日
In the next iteration, you will have a new f and ch, so each assignment will be to a new block of the array.

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

その他の回答 (2 件)

Hiro Yoshino
Hiro Yoshino 2020 年 12 月 23 日
repmat may solve your issue - check up the link:
  1 件のコメント
Haneen
Haneen 2020 年 12 月 23 日
repmat is for copying an array and concatinating; but here I am filling new data in every iteration. I am not sure how would repmat be of an help. Would you please elaborate?

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


James Tursa
James Tursa 2020 年 12 月 23 日
Something like this maybe?
k = 1;
% your loop
b = r x 1800 matrix
f = whatever
ch = whatever
r = size(b,1);
array(k:k+r-1,:,f,ch) = b;
k = k + r;
% end loop
But it is not clear how f and ch change within the loop, so this might not work as written.

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by