cell cal from function problem

3 ビュー (過去 30 日間)
Touts Touts
Touts Touts 2021 年 7 月 14 日
コメント済み: Touts Touts 2021 年 7 月 14 日
Hello, please i have a function whith 4 input values and 3 outputs
[output1, output2, output3] = Myfunc(input1, input2, input3, input4)
when I call Myfunc in a for loop i get a cell, the matrix of this cell is a one vector output
for j = 1 : 2
AA{j} = Myfunc(input1, input2, input3, input4)
end
BB = cell2mat(AA')
But I mus have
[output1, output2, output3] the j = 1
[output1, output2, output3] the j = 2
So the BB matrix must be a 3 columns and 2 rows. Thanks

採用された回答

Rik
Rik 2021 年 7 月 14 日
If you pre-allocate the cell array you can use a comma separated list:
[input1, input2, input3, input4]=deal(rand);
AA=cell(3,2);
for n = 1 : 2
[AA{:,n}] = Myfunc(input1, input2, input3, input4);
end
BB = cell2mat(AA')
BB = 2×3
0.5795 1.7180 2.7723 0.5537 1.5030 2.3653
function [output1, output2, output3] = Myfunc(input1, input2, input3, input4)
output1=rand;output2=1+rand;output3=2+rand;
end
  3 件のコメント
Rik
Rik 2021 年 7 月 14 日
If you want to covert a cell to a table, I would expect cell2table to do the trick. This wasn't specid=fied in your question, so I didn't do that in my answer.
[input1, input2, input3, input4]=deal(rand);
AA=cell(3,2);
for n = 1 : 2
[AA{:,n}] = Myfunc(input1, input2, input3, input4);
end
BB = cell2table(AA')
BB = 2×3 table
Var1 Var2 Var3 __________________ ______ ______ 0.51821 0.93848 1.9516 2.9263 0.72344 0.64505 1.781 2.087
function [output1, output2, output3] = Myfunc(input1, input2, input3, input4)
output1=rand(1,2);output2=1+rand;output3=2+rand;
end
Touts Touts
Touts Touts 2021 年 7 月 14 日
@Rik, Thanks, it work correctly

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

製品


リリース

R2009b

Community Treasure Hunt

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

Start Hunting!

Translated by