Questions about the unsure range in xlsread, when using gui

1 view (last 30 days)
When using gui to input the number of the column and row to confirm the range of the xlsread, but i am not sure how to combine it. the code is following,
serial1 = str2num(get(handles.location1,'String'));
serial2 = str2num(get(handles.location2,'String'));
col = char('B' + serial1);
row = char('D' + serial2);
location = (col:row);
rawname = handles.rawname;
%fullname = handles.fullname;
r_DATA = xlsread(rawname,'sheet1',location);
After running the code, it shows
Error using xlsread (line 260)
Data range 'FGHIJKLMNOPQRSTUVWXYZ[\]' is invalid.
Error in app>pushbutton2_Callback (line 410)
r_DATA = xlsread(rawname,'sheet1',location);
It is confused with the location

Accepted Answer

Jan
Jan on 20 Mar 2019
Edited: Jan on 20 Mar 2019
I guess you mean:
col = sprintf('B%d', serial1);
row = sprintf('D%d', serial2);
location = [col, ':', row];
or simpler:
location = sprintf('B%d:D%d', serial1, serial2);
In your code 'B' + serial1 seems to be the character 'F' and 'D' + serial2 the character ']'. Then
'F':']'
is 'FGHIJKLMNOPQRSTUVWXYZ[\]'

More Answers (1)

Walter Roberson
Walter Roberson on 20 Mar 2019

Categories

Find more on Get Started with MATLAB in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!