### Translated by

このページのコンテンツは英語から自動翻訳されています。自動翻訳をオフにする場合は「<a class="turn_off_mt" href="#">ここ</a>」をクリックしてください。

## Collecting the outputs of a function within a for loop

Nikolaos Zafirakis

### Nikolaos Zafirakis (view profile)

さんによって質問されました 2019 年 4 月 17 日

### Nikolaos Zafirakis (view profile)

さんによって コメントされました 2019 年 4 月 17 日
I’ve got a function within a for loop and I want to collect the output variables of the function. Currently, the outputs A, B, C, D give only the last number in the series.
time = 100;
for i=1:length(time)
[A,B,C,D] = Name(a,b,c,d,time);
end

#### 0 件のコメント

サインイン to comment.

## 1 件の回答

2019 年 4 月 17 日

2019 年 4 月 17 日

time = 100;
[A,B,C,D]=deal(cell(100,1)); % if the outputs are scalars then use zeros() instead of cell
for ii=1:time
[A{ii},B{ii},C{ii},D{ii}] = Name(a,b,c,d,time);
end

#### 3 件のコメント

Nikolaos Zafirakis

### Nikolaos Zafirakis (view profile)

2019 年 4 月 17 日
Thank you for your fast response. Although what you have provided is not working. The outputs are a mixture of scalar and vector quantities. If you are familiar with any other method could you please provide it to me otherwise thank you for your help!

2019 年 4 月 17 日
It’a not working doesn’t give any useful information, what error message are you getting?
Nikolaos Zafirakis

### Nikolaos Zafirakis (view profile)

2019 年 4 月 17 日
I don’t think the issue is in the code you provided me anymore because the function requires a different input than the one I previously believed this new input is a 100 vectors 1 by 6. I will let you know when I managed to compute this, although if you could provide assistance on this to I would be very happy. The plan is to add a for loop around the for loop so,
T=100
for i=1:T
C=P(100:1); % The one by six vector needs to come from C
[A,B,C,D]=deal(cell(100,1));
for ii=1:time
[A{ii},B{ii},C{ii},D{ii}] = Name(a,b,c,d,time);
end
end

サインイン to comment.

Translated by