Is there a way to change the range function of xlsread based on a variable input?
4 ビュー (過去 30 日間)
古いコメントを表示
What I want to do is to take values from a large excel file and using matlab create a text file.
Right now I have my code reading individual cell values and assigning them to a variable.
The variable is then input into a string of text using fprintf, as below,
fprintf(op, ' FIle Name : %s\n', sname);
Is there a way to take an input from a user that changes the range in the xlsread functions.
i.e. for the code below,
var = input('enter excel column: ', 's');
variable1 = xlsread('filename.xlsx', 'var4:var4');
variable2 = xlsread('filename.xlsx', 'var115:var115');
so that if, for example, a user input D
the function would read it as,
variable1 = xlsread('filename.xlsx', 'D4:D4');
variable2 = xlsread('filename.xlsx', 'D115:D115');
0 件のコメント
採用された回答
Walter Roberson
2020 年 5 月 30 日
var = input('enter excel column: ', 's');
variable1 = xlsread('filename.xlsx', sprintf('%s4:%s4', var, var));
variable2 = xlsread('filename.xlsx', sprintf('%s115:%s115', var, var));
0 件のコメント
その他の回答 (1 件)
dpb
2020 年 5 月 30 日
編集済み: dpb
2020 年 5 月 30 日
Sure (altho it's probably as fast and less hassle to just read read the whole spreadsheet and then just select the results wanted). If you really are using xlsread and calling it more than once on the same file, it's almost certainly slower because xlsread will open/close the file and the COM interface every call.
cols=input('Enter two (2) columns separated by whitespace or delimiter: ','s');
cols=string(split(cols));
rows=[4;115];
rnges=compose('%s%d:%s%d',cols,rows,cols,rows);
returns
>> rnges
rnges =
2×1 cell array
{'A4:A4' }
{'D115:D115'}
>>
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Spreadsheets についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!