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일
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 Exchange에서 Loops 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