Writing inside cell array
조회 수: 1 (최근 30일)
이전 댓글 표시
Let "f" be a function that returns a 3 by 1 cell. I have to evaluate "f" multiple times, say "N", and I would like to store the results in just one 3 by 2 cell "y".
My solution is the following and is based on a temporary 3 by 1 cell "ytemp". Is there a way to obtain the same result without involving "ytemp"?
y = cell(3, N);
for i = 1 : N
ytemp = f(i);
y(:, i) = ytemp(:);
end
댓글 수: 0
채택된 답변
추가 답변 (1개)
Sulaymon Eshkabilov
2023년 5월 17일
If understood correctly your question, here is how it can be solved:
t = randn(1);
g = sin(2*pi*t);
f = repmat(g, 1,100)+rand(size(t));
N = 100;
y = cell(1,N);
for i = 1 : N
y{1,i} = f(i);
end
y
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!