How to take values from a matlab file

1 回表示 (過去 30 日間)
Max-Henri Froger
Max-Henri Froger 2020 年 5 月 15 日
コメント済み: Max-Henri Froger 2020 年 5 月 16 日
Hi everyone,
I am on matlab 2016b. I am creating a function an appdesigner. I am asking the user to choose a matlab file. The configuration of the matlab files will always be like the photo below.
In this file, I am only interesting by the table name "essai". Like you see in the code below, I trying to import the data from the file but it's not working. I would only take the table named "essai" to save it and load it in another function.
I need help to solve this problem.
thanks

採用された回答

Geoff Hayes
Geoff Hayes 2020 年 5 月 15 日
Max-Henri - since you are loading a mat file, perhaps you can use load instead. Something like
[filename, pathname] = uigetfile({'*.mat'},'Please select a MATLAB file');
if ~isempty(pathname) && ~isempty(filename)
app.FileNameEditField.Value = filename;
myData = load(fullfile(pathname, filename));
if isfield(myData, 'essai')
essai = myData.essai;
save('essai.mat', 'essai');
end
end
The above is untested but I think it straightforward. Note how we use fullfile to create the correct path fo the file and how we check to make sure that 'essai' is a valid field of the data before we try to save it to file.
  1 件のコメント
Max-Henri Froger
Max-Henri Froger 2020 年 5 月 16 日
Thank you very much, it's working!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeTransportation Engineering についてさらに検索

製品


リリース

R2016b

Community Treasure Hunt

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

Start Hunting!

Translated by