How to use the following nested loop and store values

1 回表示 (過去 30 日間)
Zarak Khan
Zarak Khan 2017 年 11 月 22 日
編集済み: Andrei Bobrov 2017 年 11 月 22 日
Hello,
I have trouble in working the nested for loops , getting it wrong somewhere
for mult=[-0.05,-0.03,0.03,0.05];
for ii=1:45
b(ii)=20+mult;
end
end
What i want is the code, to add each value of mult from -0.05 to 0.05 separately during the 45 iterations in 2nd loop. Right now it just uses -0.05 from mult array and displays results, doesn't go to further mult array values.
Thanks

採用された回答

KSSV
KSSV 2017 年 11 月 22 日
mult=[-0.05,-0.03,0.03,0.05];
b = zeros(45,4) ;
for ii=1:45
b(ii,:)=20+mult
end

その他の回答 (1 件)

Andrei Bobrov
Andrei Bobrov 2017 年 11 月 22 日
編集済み: Andrei Bobrov 2017 年 11 月 22 日
b = mult(:)' + (1:45)'*20;
for old versions of MATLAB
b = bsxfun(@plus,mult(:)',(1:45)'*20);

カテゴリ

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