MATLAB Answers

Ziao Li
0

Questions about the unsure range in xlsread, when using gui

Asked by Ziao Li
on 20 Mar 2019
Latest activity Commented on by Ziao Li
on 20 Mar 2019
Accepted Answer by Jan
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

  0 Comments

Sign in to comment.

Tags

2 Answers

Answer by Jan
on 20 Mar 2019
Edited by Jan
on 20 Mar 2019
 Accepted Answer

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[\]'

  1 Comment

Sign in to comment.