Matlab: Create Matrix from Single Column Data

  • Thread starter Thread starter rishabhdutta
  • Start date Start date
  • Tags Tags
    Matlab
Click For Summary

Discussion Overview

The discussion revolves around creating a matrix from a single column of data in MATLAB. Participants explore methods for reshaping the data into a specified matrix format, addressing both built-in functions and manual approaches.

Discussion Character

  • Technical explanation, Homework-related

Main Points Raised

  • One participant seeks a script to convert a single column of data into a matrix of dimensions m * n, noting that m * n does not need to equal the length of the original data.
  • Another participant suggests using the built-in 'reshape' function for this task, while also mentioning that if built-in commands are not allowed, looping would be necessary.
  • A different participant expresses gratitude but indicates that 'reshape' was not suitable for their needs, as the number of elements in the desired matrix must match the original data size.
  • One participant introduces the colon (:) operator as a useful tool for extracting parts of vectors or matrices, implying its potential utility in the context of matrix manipulation.

Areas of Agreement / Disagreement

The discussion reflects a lack of consensus on the best approach to take, with differing opinions on the utility of built-in functions versus manual looping methods.

Contextual Notes

Participants highlight limitations regarding the requirement that the number of elements in the desired matrix must match the original data size, which affects the applicability of certain methods.

rishabhdutta
Messages
4
Reaction score
0
I have a single column data of say length 1000. I want to make a matrix m * n using that data. m*n may need not be 1000, it can be less. looking for the script.
 
Physics news on Phys.org
If you're allowed to use built-in commands, you can use 'reshape':
http://www.mathworks.com/help/techdoc/ref/reshape.html

If you're not, you're going to have to do some looping:
http://www.mathworks.com/help/techdoc/matlab_prog/brqy1c1-1.html

We can't do your work for you, however.
 
Last edited by a moderator:
Thank you for the effort.

Had to use looping. reshape couldn't help me much as the no. of elements in the desired matrix have to be same as in the provided matrix form. for eg. I would like to get 4*3 matrix from the 15*1 matrix
 

Similar threads

Replies
7
Views
3K
  • · Replies 8 ·
Replies
8
Views
3K
Replies
7
Views
3K
  • · Replies 0 ·
Replies
0
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 10 ·
Replies
10
Views
3K
  • · Replies 7 ·
Replies
7
Views
3K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 8 ·
Replies
8
Views
3K