how to choose a random excel cell in a certain coloum
1 次查看(过去 30 天)
显示 更早的评论
a=randi([1,7092]);
b=a+1;
dtname=['D','b'];
dt = xlsread('Final_NGA_Flatfile.xlsx','dtname':'dtname');
I want to import the data from the cell D__ where __ represents the number a+1. How do I do this? With my current code, the issue I am running into is "Error using xlsread (line 257)
Worksheet 'd' not found.
Error in New5StoryBuilding (line 44)
dt = xlsread('Final_NGA_Flatfile.xlsx','dtname':'dtname');"
0 个评论
回答(1 个)
Sindar
2020-6-27
编辑:Sindar
2020-6-27
If you have R2019a or above, use readmatrix.
But, the issue is that you are mixing up passing a variable and a string. It happens that you're code returns something slightly parseable:
>> 'dtname':'dtname'
'd'
but not what you expect. Try this:
a=randi([1,7092]);
b=a+1;
columnname="D";
dt = xlsread('Final_NGA_Flatfile.xlsx',columnname+b+":"+columnname+b);
% or
dt = readmatrix('Final_NGA_Flatfile.xlsx','Range',columnname+b+":"+columnname+b);
since
>> b=101;
>> columnname="D";
>> columnname+b+":"+columnname+b
"D101:D101"
1 个评论
Sindar
2020-6-27
note that just "D101" will probably not give you what you want, since Matlab is likely to interpret it as either the name of the sheet or as the first cell to read
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Spreadsheets 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!