Push button to fill the static text - all related to a specific excel colum row

1 view (last 30 days)
Hi, I am new to Matlab. Trying to handle figures from excel sheet, ie if clicking the push button "Search" I should have the info filled in the following static text and each of them corresponding to a specific row column in excel. My coding are follows for now:
a = xlsxread('C:\Users\Esther\Desktop\COMP1101C\Lyons Medical Scheme.xlsx'\'Employees covered'\'E14'); b = xlsxread('C:\Users\Esther\Desktop\COMP1101C\Lyons Medical Scheme.xlsx'\'Employees covered'\'F14'); c = xlsxread('C:\Users\Esther\Desktop\COMP1101C\Lyons Medical Scheme.xlsx'\'Employees covered'\'G14'); d = xlsxread('C:\Users\Esther\Desktop\COMP1101C\Lyons Medical Scheme.xlsx'\'Employees covered'\'H14');
%display “a” in the static text component when the %pushbutton is pressed set(handles.dob_staticText,'String',a); set(handles.policynum_staticText,'String',b); set(handles.date_staticText,'String',c); set(handles.planOption_staticText,'String',d);
Please help.

Answers (1)

Image Analyst
Image Analyst on 16 Sep 2018
Edited: Image Analyst on 16 Sep 2018
Here is how to format your code:
What is the function xlsxread()? Why not use the built-in xlsread()?
If "a" etc. are simple numbers, not strings, you can use num2str():
handles.dob_staticText.String = num2str(a);
handles.policynum_staticText.String = num2str(b);
handles.date_staticText.String = num2str(c);
handles.planOption_staticText.String = num2str(d);
Or, if you really have R2008 (an antique 10 year old version), you have to use set():
set(handles.dob_staticText,'String', num2str(a));
set(handles.policynum_staticText,'String', num2str(b));
set(handles.date_staticText,'String', num2str(c));
set(handles.planOption_staticText,'String', num2str(d));
  2 Comments
ET1994
ET1994 on 16 Sep 2018
Thanks for your revert back, my final code is this now, there is no error when run but the informations do not appear.
a=xlsread('C:\Users\Esther\Desktop\COMP1101C\Lyons Medical Scheme.xlsx'\'Employees covered'\'E14');
b=xlsread('C:\Users\Esther\Desktop\COMP1101C\Lyons Medical Scheme.xlsx'\'Employees covered'\'F14');
c=xlsread('C:\Users\Esther\Desktop\COMP1101C\Lyons Medical Scheme.xlsx'\'Employees covered'\'G14');
d=xlsread('C:\Users\Esther\Desktop\COMP1101C\Lyons Medical Scheme.xlsx'\'Employees covered'\'H14');
%display "a" in the dob_staticText component;
%display "b" in the policynum_staticText component;
%display "c"in the date_staticText component;
%display "d" in the planOption_staticText component; when the
%info_pushbutton is pressed
set(handles.dob_staticText,'String', num2str(a));
set(handles.policynum_staticText,'String', num2str(b));
set(handles.date_staticText,'String', num2str(c));
set(handles.planOption_staticText,'String', num2str(d));
Image Analyst
Image Analyst on 16 Sep 2018
I don't know how this could work. What does it mean to divide a character array 'C:\Users\Esther\Desktop\COMP1101C\Lyons Medical Scheme.xlsx' by another character array 'Employees covered'? It seems like that should throw an error.
Anyway, assuming you get the badly-named a, b, c, and d, they are probably arrays, not single scalars. What does this show in the command window if you put it after your calls to xlsread():
whos a
whos b
whos c
whos d

Sign in to comment.

Tags

Products


Release

R2008a

Community Treasure Hunt

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

Start Hunting!