0

I'm designing a gui and I am trying to load a mat file into a struct and then access data from the struct. I also want to print the variables in the struct to see if the variables are in the mat file and they work. Thanks, I also don't have much experience in matlab. Here is my code:

function pushbutton5_Callback(hObject, eventdata, handles)
%get path
[FileName,PathName] = uigetfile('*.mat','Select mat file');

if (FileName==0) %cancel is pressed
    return;
end

Struct1 = load('FileName');
Structname = fieldnames(Sruct1);


MatDef = [PathName FileName]; %path and name
set(handles.edit2,'String',MatDef) %shows directory string

Right now I am getting errors trying to load the mat file into a struct.

1 Answer 1

0

Try replacing with the following:

[FileName,PathName] = uigetfile('*.mat','Select mat file');
if FileName==0, return, end

Struct1 = load( fullfile(PathName,FileName) );   %# pass file path as string
Structname = fieldnames(Struct1);                %# typo?
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.