Error: Array indices must be positive integers or logical values.
17 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Katherine DeChambeau
el 28 de Feb. de 2021
Respondida: Walter Roberson
el 28 de Feb. de 2021
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 comentarios
Respuesta aceptada
Más respuestas (1)
Bjorn Gustavsson
el 28 de Feb. de 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
0 comentarios
Ver también
Categorías
Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!