Loading variables in GUI
Afficher commentaires plus anciens
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 5000x4 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 5000x4
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;
end
guidata(hObject,handles);
5 commentaires
Mike Beacham
le 24 Juil 2014
Geoff Hayes
le 24 Juil 2014
The above error makes sense given that there is no local variable file to assign to handles.file. What should file be in this case?
As for uiopen it opens and loads data from a file given the handles.filename. But since "filter* is based on the name and the extension of handles.filename (which is different from handles.file??) then there doesn't seem to be any reason to use this function - since the user has no choice.
Mike Beacham
le 24 Juil 2014
Geoff Hayes
le 25 Juil 2014
Mike - I don't understand how changing file to handle.file makes a difference. What is handle? But then what does the calculate button callback actually do, since there doesn't appear to be any calculations?
Mike Beacham
le 25 Juil 2014
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Workspace Variables and MAT Files dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!