refer to excel data using excel column numbers ?

I read in a large excel data file using readmatrix :
data = readmatrix('press.xlsx');
I would like to refer to the data by the original column names in excel - for example, for the third column, something like :
x = data(:,'C')
This runs but produces wrong results - Any way to make this work ? Thanks

回答 (1 件)

Voss
Voss 2023 年 7 月 14 日

0 投票

Use readtable instead of readmatrix.

3 件のコメント

Voss
Voss 2023 年 8 月 15 日
@Ambady Suresh: Did this answer work for you?
Ambady Suresh
Ambady Suresh 2023 年 8 月 16 日
@Voss - Yes and No. The read table works as you suggest with column names. However, the return type is different. So I kept getting errors like Operator '-' is not supported for operands of type 'table', etc.
Voss
Voss 2023 年 8 月 16 日
編集済み: Voss 2023 年 8 月 16 日

When data is a table, you would say:

x = data{:,'C'}

or:

x = data.C

Please see:

https://www.mathworks.com/help/matlab/matlab_prog/access-data-in-a-table.html

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

タグ

質問済み:

2023 年 7 月 14 日

編集済み:

2023 年 8 月 16 日

Community Treasure Hunt

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

Start Hunting!

Translated by