Filter löschen
Filter löschen

How can I select a specific variable in the .mat file which contains different variables in the user interface?

5 Ansichten (letzte 30 Tage)
Hi! I want to design an app which can draw with a .mat file. How can I select a specific variable in the .mat file which contains different variables in the user interface? By 'text area' or something?

Akzeptierte Antwort

Fangjun Jiang
Fangjun Jiang am 5 Dez. 2019
  1. Use load() with return structure.
gongStruct = load('gong.mat');
fieldnames(gongStruct)
  1. Use matfile object.
Help matfile

Weitere Antworten (1)

Cam Salzberger
Cam Salzberger am 5 Dez. 2019
Bearbeitet: Cam Salzberger am 5 Dez. 2019
Hello Kunpeng,
You may consider using whos to determine the variables available in a MAT file. Then you can specify the variable you want when you call load based on the user selection. This will be faster than loading the entire MAT file into the workspace, unless you expect the user to frequently switch between what they want loaded.
You may also consider checking out the matfile object, as Fangjun suggested.
-Cam
  5 Kommentare
Stephen23
Stephen23 am 10 Mär. 2020
"I have solved this problem with eval() function!"
A much better** solution is to load into an output variable, just like Fangjun Jiang's Answer shows, and then access its fields:
** better in the sense faster, more efficient, more robust, less buggy, much easier to debug. The approach you are using is not recommended:
Kunpeng Zhang
Kunpeng Zhang am 14 Mär. 2020
Wow,that is awesome!!!I will study and try alternative methods. Thank you for your advice!!

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Workspace Variables and MAT-Files finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by