开发者

MATLAB loading .mat files from gui and accessing variables inside the struct

开发者 https://www.devze.com 2023-03-14 22:19 出处:网络
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

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',MatDe开发者_如何学Pythonf) %shows directory string

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


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?
0

精彩评论

暂无评论...
验证码 换一张
取 消