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

조회 수: 3 (최근 30일)
Donovan Allum
Donovan Allum 2021년 12월 11일
댓글: Priyanka Kondapalli 2021년 12월 15일
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개)

카테고리

Help CenterFile Exchange에서 Data Import from MATLAB에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by