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.

Shai
  • 111,146
  • 38
  • 238
  • 371
Khoa
  • 3
  • 1
  • 3

1 Answers1

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?
Amro
  • 123,847
  • 25
  • 243
  • 454