フィルターのクリア

How i create a structure from an excell document that i import into matlab ?

1 回表示 (過去 30 日間)
Leonidas Tempelis
Leonidas Tempelis 2021 年 4 月 8 日
編集済み: Jan 2021 年 4 月 8 日
I have an excell table with dimencions (9x8). I want to import the table in matlab and then create a structure with 8 fields. Each field will have the values of each row, so the dimencions would be 9x1.
I tried to import the excell table as 8 cell arrays, where every column from the table will be an individual cell array. Then i tried create a stuctrure with 8 fields where each field would correspond to each cell. The following code describes whta i have done already
H = struct ( field1, value1, field2, value2, field3, value3, field4, value4, field5, value5, field6, value6, field7, value7, field8, value8);
H.value1 = ORIGIN;
H.value2 = DESTINATION;
H.value3 = EARLIESTPICKUPTIME;
H.value4 = LATESTDELIVERY;
H.value5 = TRANSPORTATION;
H.value6 = MODEOFTRANSPORT;
H.value7 = HRS;
H.value8 = KM;
I have a probem because when i run the code, Matlab does not understand the field1, field2 etc
excell:
  3 件のコメント
Leonidas Tempelis
Leonidas Tempelis 2021 年 4 月 8 日
I uploaded a screenshot to my question. thank you very much
Jan
Jan 2021 年 4 月 8 日
Please post the complete code. What is the contents of the variables "field1"?
Post the Excel file as attached file. We cannot use the screenshot to check the suggested code.

サインインしてコメントする。

回答 (1 件)

Jan
Jan 2021 年 4 月 8 日
編集済み: Jan 2021 年 4 月 8 日
What about:
T = readtable(ExcelFile, 'ReadVariableNames', true);
S = table2struct(T, 'ToScalar', true)

カテゴリ

Help Center および File ExchangeSpreadsheets についてさらに検索

タグ

製品


リリース

R2014b

Community Treasure Hunt

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

Start Hunting!

Translated by