How do I loop over readmatrix?

4 ビュー (過去 30 日間)
Samuel barton
Samuel barton 2020 年 8 月 11 日
回答済み: Walter Roberson 2020 年 8 月 11 日
I have an excel file and I want to grab every 21st row out and label each row G_21,G_42 and so on. I am not sure how to do this?

採用された回答

Walter Roberson
Walter Roberson 2020 年 8 月 11 日
In order to do that without reading all of the other rows and throwing out the other rows, then you need to know the last row (or the last row you want to import anyhow.) I will call that LastWantedRow below
filename = 'appropriatename.xlsx';
opts = detectImportOptions(filename);
rows = 21:21:LastWantedRow;
opts.DataRange = [rows; rows].'; %two column matrix, start and end row numbers
t = readmatrix(filename, opts);
However, you can only add row labels for table() and timetable() objects, not for matrices. readmatrix() is (mostly) for numeric matrix. You could construct
rownames = "G" + rows;
but you cannot attach those to a numeric matrix.

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by