Array indices must be positive integers or logical values
Afficher commentaires plus anciens
I am trying to model a step input to a damped spring-mass system. Code is pretty simple as pasted below:
%% Parameters
k = 70e3;
mq = 20;
c_crit = 2360;
c = 2294.38;
z = c/c_crit;
n_freq = sqrt(k/mq);
d_freq = n_freq*sqrt(1-z^2);
F0 = 412.02;
%%
Ts = 1/1000;
t = [0:Ts:0.3-Ts];
Q = F0/n_freq^2;
R = exp(-z*n_freq.*t);
S = (z*n_freq)/d_freq;
x = Q(1-R(cos(d_freq.*t) + S*sin(d_freq.*t)));
I'm getting the error stated due to the function x. I've not much experience with MATLAB and I have no idea what the problem is. Any tips would be appreciated!
1 commentaire
Torsten
le 22 Fév 2022
Two multiplication signs are missing in the definition of x.
Réponses (1)
Image Analyst
le 22 Fév 2022
0 votes
A thorough discussion of the error is in the FAQ:
Q is an array and you are trying to get an element that is whatever the value of this expression is:
1-R(cos(d_freq.*t) + S*sin(d_freq.*t))
and I bet that is not an integer like 1,2,3,etc. It can't be zero. It can't be negative (there is no -1 row of a matrix). It can't be a fraction. There is no 2.4th row of a matrix - it must be either 2 or 3, not 2.4.
Catégories
En savoir plus sur Introduction to Installation and Licensing dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!