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

14 次查看(过去 30 天)
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 个评论
Mathieu NOE
Mathieu NOE 2021-12-13
编辑:Mathieu NOE 2021-12-13
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 2021-12-15
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

请先登录,再进行评论。

回答(0 个)

产品


版本

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by