How to import Excel table with column of as individual variables?

14 ビュー (過去 30 日間)
Joey Otanez
Joey Otanez 2021 年 11 月 19 日
回答済み: Peter Perkins 2021 年 11 月 23 日
How would I import a table from Excel such as this
to load into my workspace as this?
Using the readtable function inputs it as a table with a column of the names and a column for values (except the fts2mph and mph2fts which show up as NaN but that's another issue)
idk how to convert it to individual variables from the table or if there's a direct way to create the variables from the Excel file

採用された回答

Cris LaPierre
Cris LaPierre 2021 年 11 月 19 日
編集済み: Cris LaPierre 2021 年 11 月 19 日
Try the rows2vars function on the result of readtable. It reorients a table so that rows become variables.
The variables will still be part of a table (columns of a table are the variables), so they will not show up individually in your workspace, but you can access them using table.varName notation (see here).
  4 件のコメント
Joey Otanez
Joey Otanez 2021 年 11 月 19 日
Executing that code results in a 1x2 cell array of Var1 and Var2
Cris LaPierre
Cris LaPierre 2021 年 11 月 19 日
Those are your variable names.
Look through the examples on the rows2vars documentation page. This is expected. You will need to use the 'VariableNameSource' name-value pair to name the new table variables something else.

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

その他の回答 (1 件)

Peter Perkins
Peter Perkins 2021 年 11 月 23 日
I don't know that readtable is the way to go here. If you really just have a few named scalars, you might think about readcell (since R2019a), and then create a scalar struct named constants with one field for each of rhoSL aSL, etc. You could also poof them into your workspace using eval, but that's usually considered bad form.

カテゴリ

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

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by