How to store and use table variable name

6 ビュー (過去 30 日間)
Jack Oswald
Jack Oswald 2020 年 11 月 16 日
コメント済み: Jack Oswald 2020 年 11 月 16 日
I'm creating a function to grab data from a hefty Excel sheet. I want the function input to determine the data I grab. Ex, in this case prices is the column header (table variable name) for the data I care about.
grab_data('12345.xlsx','prices')
function data_out = grab_data(filename,data_to_grab)
data=readtable(filename);
for h = [1:height(data)]
data_out(end+1)=data.data_to_grab(h)
end
end
When I run something like this, I get an error that there is no table variable name 'data_to_grab'. It's reading the name of the variable literally. Please help!

採用された回答

Walter Roberson
Walter Roberson 2020 年 11 月 16 日
data_out(end+1) = data.(data_to_grab)(h)
  1 件のコメント
Jack Oswald
Jack Oswald 2020 年 11 月 16 日
Thanks!

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

その他の回答 (0 件)

カテゴリ

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