MATLAB Vector concatenation without using a for loop (MATLAB)

Click For Summary
Concatenating a variable number of vectors in MATLAB can be achieved without using a for loop by utilizing the 'reshape' function. If the vectors are stored in a matrix, they can be easily reshaped into a single vector. This method is efficient and adapts to different input parameters. Users can read data from files using commands like 'dlmread' to create the matrix. Overall, 'reshape' provides a straightforward solution for vector concatenation in MATLAB.
wkleonard
Messages
1
Reaction score
0
I have a variable number of vectors to concatenate in my Matlab model. Is there a way to do this without a for loop? The number will depend upon input parameters. Suggestions.
 
Physics news on Phys.org
If they are stored in a matrix (as then tend to be when read from a file with e.g. dlmread), you can reshape the matrix into a vector with the cleverly named command 'reshape'.
 

Similar threads

  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 32 ·
2
Replies
32
Views
4K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
Replies
3
Views
2K
  • · Replies 9 ·
Replies
9
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 9 ·
Replies
9
Views
4K