Using Matfile() in combination with a variable
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Jan Majewski
am 21 Nov. 2018
Bearbeitet: Jan Majewski
am 22 Nov. 2018
I reference a Matfile and to access its entries using a variable:
a = 'variablefrommat';
m = matfile('myMat.mat');
x = m.a
This results (obviously) in Matlab searching the Matfile for 'a'. In my case this error occurs:
'a' does not exist in 'myMat.mat'.
Is there a way to interpret 'a' as the variable?
0 Kommentare
Akzeptierte Antwort
Weitere Antworten (1)
Geoff Hayes
am 21 Nov. 2018
Jan - if you know the name of the variable that you want to reference then why are you setting this to its own variable? What are you trying to accomplish here?
x = getfield(m,a)
which will return the expected result...but do you need to do it this way?
1 Kommentar
Siehe auch
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!