Loop over a vector and store value in new vector error

Hello,
I am currently trying to loop over a vector b1 and store the new values in a vector m1. I have the following code:
r1 = 4
r2 = 3
b1 = [0.8,0,0,0.1,0.1,0,0]
for i = b1(1:6)
m1(i)= (1/(1+w1-r1))*(w1*i)
end
But MATLAB states "Attempted to access m1(0.8); index must be a positive integer or logical". Is there any command I could use that support non-integers?

 採用された回答

Star Strider
Star Strider 2017 年 7 月 31 日

1 投票

In MATLAB, subscripts must be integers greater than zero.
This would work:
w1 = 42; % Create Data
r1 = 4
r2 = 3
b1 = [0.8,0,0,0.1,0.1,0,0]
for i = 1:numel(b1)
m1(i)= (1/(1+w1-r1))*(w1*b1(i));
end

2 件のコメント

DineMATLAB
DineMATLAB 2017 年 7 月 31 日
It works, thank you very much!
Star Strider
Star Strider 2017 年 7 月 31 日
As always, my pleasure!

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および 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