0

I am trying to save a 1D array into a table in MATLAB. I would like the data to be saved in one column, with 5 rows of data, not 5 columns with one row of data (shown below).

testarray = [1:5];

testarray =

 1     2     3     4     5  

t=table(testarray);

t=array2table(testarray)

t =

testarray1    testarray2    testarray3    testarray4    testarray5
__________    __________    __________    __________    __________

1             2             3             4             5         

What I would like the output to look like:

t =

testarray
_________
1 
2 
3 
4 
5

If anyone has any idea of how I can make this work, please let me know!

0

1 Answer 1

1

MATLAB's table objects are row-oriented, and MATLAB makes no assumptions about the shape of your data for the ambiguous vector case.

Because [1:5] is a row vector:

>> [1:5]

ans =

     1     2     3     4     5

MATLAB will treat this as one row of data.

Because you want column-oriented data, you will need to transpose this vector:

>> [1:5].'

ans =

     1
     2
     3
     4
     5

In order for MATLAB to treat it as a single variable (column):

>> testarray = [1:5];
t = table(testarray.')

t = 

    Var1
    ____

    1   
    2   
    3   
    4   
    5   
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.