How do I import excel data to a table which has vectors as entries?

11 views (last 30 days)
Here is an example of what I am thinking:
mystruct.list = [1 2 3 4 5];
mytable = struct2table(mystruct);
mytable
If you run this short snippet you print the table 'mytable' which will be a single row where each of these rows belows to the single column of the table titled 'list'. What I want to do is the reverse:
newstruct = table2struct(importedtable);
but this time mytable is imported from excel (or another program like it). The problem I'm encountering is a way to format the data in excel or modify the import procedure so that 'importedtable' has the same form as mytable.
Fortunately for me, the data I'm using is not big (the actual vectors are 1x5) so I can probably just write a script which carries this out for me but I'd like it to be simpler if possible. Also the data I'm importing are strings, not numbers.
  2 Comments
Mathieu NOE
Mathieu NOE on 13 Dec 2021
Edited: Mathieu NOE on 13 Dec 2021
hello
not sure to understand what you are trying to do
maybe you should share the excel file and write how the result should be
Priyanka Kondapalli
Priyanka Kondapalli on 15 Dec 2021
Hello,
I understand that you are having data in excel and want to load into MATLAB table with a single column.
You can use "xlsread()" function to load excel data into MATLAB. This function stores data in the form of matrix.
If the data in excel is in a column, you will get a column vector in MATLAB, below code should do the task
>>data = xlsread(filename)
>>array2table(data);
If the data in excel is in a row, you will get a row vector in MATLAB, then just apply the transpose after loading into MATLAB
>>data = xlsread(filename)
>>array2table(transpose(list));
Refer the links for more information in xlsread and array2table:
Hope this solution helps

Sign in to comment.

Answers (0)

Products


Release

R2020a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!