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

4 ビュー (過去 30 日間)
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

採用された回答

Walter Roberson
Walter Roberson 2016 年 10 月 31 日
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 件のコメント
Walter Roberson
Walter Roberson 2016 年 10 月 31 日
[filename, foldername] = uigetfile('*.mat', 'Select a mat file');
fullname = fullfile(foldername, filename);
temp = load(fullname);
fn = fieldnames(temp);
x1 = temp.(fn{1});
Sergio Callau Medrano
Sergio Callau Medrano 2019 年 12 月 3 日
thanks Walter, that is what I am looking for

サインインしてコメントする。

その他の回答 (2 件)

KSSV
KSSV 2016 年 10 月 31 日
編集済み: KSSV 2016 年 10 月 31 日
filename = uigetfile({'*.mat'}, 'Select mat file');
load(filename)
or
load('yourmatfile') ; % directly be in the folder and load the file.
doc load
  1 件のコメント
Dominika
Dominika 2016 年 10 月 31 日
I try it but program stay...nothing do it. I don´t know where is a problem :/

サインインしてコメントする。


Alexandra Harkai
Alexandra Harkai 2016 年 10 月 31 日
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')
  1 件のコメント
Dominika
Dominika 2016 年 10 月 31 日
no my file are different, for example: z1.mat, t.mat and others. And I want to load one subject .mat from file and save from workspace but condition is that z1.mat = x1 in workspace.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeApp Building についてさらに検索

タグ

タグが未入力です。

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by