Error: Array indices must be positive integers or logical values.
Ältere Kommentare anzeigen
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!
Akzeptierte Antwort
Weitere Antworten (1)
Bjorn Gustavsson
am 28 Feb. 2021
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
Kategorien
Mehr zu Creating and Concatenating Matrices finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!