フィルターのクリア

storing data in an array from a loop

1 回表示 (過去 30 日間)
Tristan
Tristan 2013 年 10 月 7 日
回答済み: Jan 2013 年 10 月 7 日
I have:
A1=(1:1:10)*1.22';
A2=(1:1:10)*2.55';
for cc=(A1+A2)/2;
G1=[1 2];
G2=[2.6 1.1];
X=(fsolve(@(x)sum(G1.*sin(G2.*x)),cc))'
end
and I want the results for X to be stored in an array

採用された回答

Inge
Inge 2013 年 10 月 7 日
A1=(1:1:10)*1.22';
A2=(1:1:10)*2.55';
i=1;
for cc=(A1+A2)/2;
G1=[1 2];
G2=[2.6 1.1];
X(i)=(fsolve(@(x)sum(G1.*sin(G2.*x)),cc))'
i = i+1;
end
I think this will work!

その他の回答 (1 件)

Jan
Jan 2013 年 10 月 7 日
The code looks strange. Perhaps you meant:
index = (1:10) * ((1.22 + 2.55) / 2);
G1 = [1 2]; % Move constants out of the loop
G2 = [2.6 1.1];
X = zeros(1, 10);
for k = 1:10
X(k) = fsolve(@(x)sum(G1.*sin(G2.*x)), index(k))';
end
Or perhaps X should be a cell?
X = cell(1, 10);
for k = 1:10
C{k} = ...

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by