I need load data .mat from file to my workspace. I used this code: filename = uigetfile({'*.mat'}, 'Select mat file'); but it´s non-functional. I need load data .mat to workspace and save to value with name x1. Is here somebody who know help? T
14 views (last 30 days)
Show older comments
Dominika
on 31 Oct 2016
Commented: Sergio Callau Medrano
on 3 Dec 2019
I need load data .mat from file to my workspace. I used this code: filename = uigetfile({'*.mat'}, 'Select mat file'); but it´s non-functional. I need load data .mat to workspace and save to value with name x1. Is here somebody who know help? T
0 Comments
Accepted Answer
Walter Roberson
on 31 Oct 2016
temp = load('z1.mat');
fn = fieldnames(temp);
x1 = temp.(fn{1});
This will load the "first" variable stored in the .mat file into the variable "x1".
3 Comments
Walter Roberson
on 31 Oct 2016
[filename, foldername] = uigetfile('*.mat', 'Select a mat file');
fullname = fullfile(foldername, filename);
temp = load(fullname);
fn = fieldnames(temp);
x1 = temp.(fn{1});
More Answers (2)
Alexandra Harkai
on 31 Oct 2016
If you know your file will be named data.mat, you don't need uigetfile, simply load will do that for you:
x1 = load('data.mat')
See Also
Categories
Find more on Workspace Variables and MAT-Files in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!