Array indices must be positive integers or logical values. Error in (line 8) mr(t)=mi-(​(mi-mf)*(t​./tb));

mi=2290000
mf=130000
tb=165
t= linspace(6.5,165,1);
mr(t)=mi-((mi-mf)*(t./tb));
mr=[]
for t=6.5:165;
mr(t)=mi-((mi-mf)*(t./tb));
end
I have no idea what's wrong with the for loop, and I don't see an error in line 8. Any help please?

 採用された回答

Stephan
Stephan 2019 年 11 月 29 日
編集済み: Stephan 2019 年 11 月 29 日
I doubt you want t to have only one point. Also no for loop is needed:
mi=2290000;
mf=130000;
tb=165;
t=linspace(6.5,165);
mr=mi-((mi-mf)*(t/tb));
plot(t,mr)

その他の回答 (2 件)

Hi,
Yo have 2 errors. First you have the line when you define the vector time:
t=linspace(6.5,164,1) % You need to put the number of points (you have only one point)
You dont need to put mr(t), because t isnt integer and you need a integer (is a index of the vector). you need to put only this line
mr=mi-((mi-mf)*(t./tb));
You dont need the loop for
Rafael
Image Analyst
Image Analyst 2019 年 11 月 29 日

0 投票

You can't have the 6.5th element of an array. You can have the 6th or 7th but not the 6.5th. Your question is a FAQ, so read the FAQ on it, plus on several other common errors and other fascinating things.

カテゴリ

ヘルプ センター および File Exchange で Introduction to Installation and Licensing についてさらに検索

質問済み:

2019 年 11 月 29 日

回答済み:

2019 年 11 月 29 日

Community Treasure Hunt

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

Start Hunting!

Translated by