Error: Array indices must be positive integers or logical values.
18 ビュー (過去 30 日間)
古いコメントを表示
Katherine DeChambeau
2021 年 2 月 28 日
回答済み: Walter Roberson
2021 年 2 月 28 日
Here is my code:
clc;clear;
t=[0:0.5:60];
h(t)=2.03*t.^2-0.0013*t.^4+0.000034*t.^4.751;
plot(t, h(t));
xlabel('Time');
ylabel('Height(m)');
But I get this error when I try to evaluate:
Array indices must be positive integers or logical values.
I need 100 values from 0 to 60 for my graph.
Thank you!
0 件のコメント
採用された回答
その他の回答 (1 件)
Bjorn Gustavsson
2021 年 2 月 28 日
Matlab has the convention that arrays-indexes starts from 1. Arrays have to be indexed with integers.
You can solve your problem in 2 ways. Either you simply assign the values you want directly to the array:
h = 2.03*t.^2 - 0.0013*t.^4 + 0.000034*t.^4.751;
or you define a function for h:
h = @(t) 2.03*t.^2 - 0.0013*t.^4 + 0.000034*t.^4.751;
In the first case you simply plot the 2 arrays:
plot(t,h)
In the second case you plot the function:
plot(t,h(t))
It seems you're very new to matlab - therefore I recommend you to look through the on-ramp material to get up to speed as fast as possible.
HTH
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Creating and Concatenating Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!