Hi, I'm trying to make my first (successful) GUI here, and I'm getting close. I have all my callbacks working, functions do what they are supposed to, but I'm having a heck of a time getting MATLAB to load the input data correctly. What I'm trying to load is a 5000×4 table with columns Datestr/Number/Number/Number. However, I am having terrible luck.
When I used load, it read my Datestr as a number and only gave me the first digit.
When I use open it gives me a struct, which I can work with, but it's a tedious work around.
When I use uiopen, I don't know how to get the file to work with the rest of my GUI.
If I can make it work, using uiopen is ideal because it lets enduser just choose the file they want. However, if they don't choose the text string in my GUI, I dont' know how to read the file. Included below is my most recent attempts at coding it in, but I keep getting invalid file errors.
% --- Executes on button press in loadbutton.
function loadbutton_Callback(hObject, eventdata, handles)[pathstr,name,ext] = fileparts(handles.filename);uiopen(strcat(name,ext));file=name; |<---- THIS LINE IS GIVING ME PROBLEMS! How do I fix it?|if iscell(file) handles.file=cell2table(file);elseif istable(file) handles.file=file;%This is good!
else handles.file=array2table(file);end
Basically, what I'm running into is rather than saving the variable named 'Name' as something, it's just saving the string as it. so I get file = 'March2011' not file = March2011 Table 5000×4
Also, When I am trying to callback this later, I might be having problems there, but I don't think I am. That bit of code is
function calculatebutton_Callback(hObject, eventdata, handles)% hObject handle to calculatebutton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
if isempty(handles.file) error('File to load?')else handles.file=file;endguidata(hObject,handles);
Best Answer