Andrea Caroppo
Andrea Caroppo

Reputation: 41

concatenate arrays of data in MATLAB

I have a set of features in a FOR cycle in MATLAB:

 for i = step:indexmax
         Posture(i) = 0;
         MotionLevel(i) = randi(10)/100 ;
         PositionX(i) = 50;
         PositionY(i) = 50;
         PositionZ(i) = 50;
         Features(i) = [Posture(i) MotionLevel(i) PositionX(i) PositionY(i) PositionZ(i)];
  end

when I arrive at the row with the definition of the array Features I have the error:

"In an assignment A(I) = B, the number of elements in B and I must be the same."

I need to concatenate the features in only one vector ( the output can be a matrix with i rows and 5 colums...)

Upvotes: 0

Views: 56

Answers (2)

cmoxiv
cmoxiv

Reputation: 46

If you are sure they are all the same size, you probably are mixing rows with columns between the [...].

Upvotes: -1

learnvst
learnvst

Reputation: 16193

In your code, you try to assign an row vector to a single element of Features. Simply index the whole row of Features

Features(i,:) = [Posture(i) MotionLevel(i) ...

Upvotes: 2

Related Questions