How to overcome an invalid use of operator error

3 visualizaciones (últimos 30 días)
Adam Reyes
Adam Reyes el 31 de Oct. de 2018
Comentada: Adam Reyes el 4 de Nov. de 2018
Hello, I am trying to populate a 60x6 matrix with random values for different variables (force, torque, radius, etc) as its columns. Each of the variables must iterate 60 times and fall between a given range. I attempted to make a column vector for each variable and implement them into the matrix, however I am receiving an error when doing so.
Pop=ones(60,6);
F=ones(60,1);
P=ones(60,1);
T=ones(60,1);
r=ones(60,1);
t=ones(60,1);
range of values
x=1;
while x<61
F(x)=99000.*rand(60,1)+1000;
P(x)=999000.*rand(60,1)+1000;
T(x)=4990.*rand(60,1)+10;
r(x)=0.04.*rand(60,1)+0.05;
t(x)=0.0008.*rand(60,1)+0.0001;
Pop=(:,1)= F(60,1);
Pop=(:,2)= P(60,1);
Pop=(:,3)= T(60,1);
Pop=(:,4)= r(60,1);
Pop=(:,5)= t(60,1);
x=x+1
end

Respuesta aceptada

KSSV
KSSV el 31 de Oct. de 2018
Editada: KSSV el 31 de Oct. de 2018
for i = 1:60
F=99000.*rand(60,1)+1000;
P=999000.*rand(60,1)+1000;
T=4990.*rand(60,1)+10;
r=0.04.*rand(60,1)+0.05;
t=0.0008.*rand(60,1)+0.0001;
pop = [F P T r t]
end
  1 comentario
Adam Reyes
Adam Reyes el 4 de Nov. de 2018
Thanks. I was getting 0 values on the last two columns but I turned the matrix into a table. Ended up being the last two columns had very small values.

Iniciar sesión para comentar.

Más respuestas (1)

madhan ravi
madhan ravi el 31 de Oct. de 2018
Should be
F(60,1)=Pop(:,1);
P(60,1)=Pop(:,2);
T(60,1)=Pop(:,3);
r(60,1)=Pop(:,4);
t(60,1)=Pop(:,5);
  1 comentario
madhan ravi
madhan ravi el 31 de Oct. de 2018
Editada: madhan ravi el 31 de Oct. de 2018
Use proper declaration properly in order to avoid the error like the above. Anyhow there are many errors in your code just wanted to point out this mistake.

Iniciar sesión para comentar.

Categorías

Más información sobre Matrices and Arrays 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!

Translated by