Push button to fill the static text - all related to a specific excel colum row
1 view (last 30 days)
Show older comments
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.
0 Comments
Answers (1)
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
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
See Also
Categories
Find more on Spreadsheets in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!