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

12 ビュー (過去 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 Center および File ExchangeSpreadsheets についてさらに検索

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by