Populating an array with a vairable-output function

How can I concatenate the outputs of a function together, when the size of the output varies? E.g.
fileBatch = {'File1','File2','...FileN'}
for f = 1:length(fileBatch)
OutputInformationTable(:,:,f) = fcn(fileBtach(f))
end
where the array returned by fcn could be 1x10, 3x12, etc. My current implementation throws a fault if the size of the returned array changes across iterations of the loop (even if the second iteration returns a smaller array). I do not have enough knoweldge about the files to pre-allocate the OutputInformationTable array.

 採用された回答

Matt J
Matt J 2021 年 5 月 21 日
編集済み: Matt J 2021 年 5 月 21 日

0 投票

Use a cell array instead.
fileBatch = {'File1','File2','...FileN'}
for f = 1:length(fileBatch)
OutputInformationTable{f} = fcn(fileBtach(f))
end

1 件のコメント

Gabriel Stanley
Gabriel Stanley 2021 年 5 月 24 日
編集済み: Gabriel Stanley 2021 年 5 月 24 日
Thanks Matt, this worked wonders. I had assumed that because fcn returns a cell array, OutputInformationTable would itself be a cell array (and trying to pre-allocate it as a cell array with dummy dimensions didn't work).

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeLoops and Conditional Statements についてさらに検索

製品

リリース

R2019b

質問済み:

2021 年 5 月 21 日

編集済み:

2021 年 5 月 24 日

Community Treasure Hunt

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

Start Hunting!

Translated by