Using Matfile() in combination with a variable
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
更多回答(1 个)
Geoff Hayes
2018-11-21
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?
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Workspace Variables and MAT-Files 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!