How to use a variable name as an Excel range?

5 ビュー (過去 30 日間)
Lexington Stoyell
Lexington Stoyell 2018 年 2 月 16 日
回答済み: Image Analyst 2018 年 2 月 17 日
I want to be able to use my variable, Value_Col, as the range which the Excel file references to find the column. The column is not always located in the same place so I am not able to use conventional methods like:'B2:B' to locate the correct column.

回答 (1 件)

Image Analyst
Image Analyst 2018 年 2 月 17 日
Try something like this:
cellReference = sprintf('A%d:C%d', rowA, rowC); % Create cell reference
[numbers, strings, raw] = xlsread(filename, sheetname, cellReference);
where rowA and rowC are numerical variables saying what rows you want to read in.
Basically you can use sprintf() to build up any cell reference in the standard "A1:B2" style, then pass that in to xlsread().

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by