how to convert fields of a struct into numbered matrices
1 次查看(过去 30 天)
显示 更早的评论
hello, I am trying to convert the fields of a 15X1 struct into numbered arrays from 1 to 15. I want to store every single field in different matrix in order to access it by just calling the name of the corresponding matrix e.g N1(name of the matrix) for the 1st field, N2 for the second field etc... I do not know if this applicable. Is there any way of doing it? And after all is there any point of doing so?
thank you in advance
0 个评论
采纳的回答
Orion
2014-11-7
编辑:Orion
2014-11-7
Hi,
you can create variables using eval
% create the variable N1,...,N5
for i = 1:5
eval(['N' num2str(i) '=rand();']);
end
you can do this with any kind of expression.
BUT : the use of eval is dangerous, because when you debug, you will not find the name of the variables. Meaning, if you search the variable N4 with the find files , you will never find it, beacause there is no line like N4 = ...
then, if the expression used in eval is long and/or complicated, it will be very tricky to debug.
Also, if you plan to deploy your application, with the compiler, eval could not work in the standalone.
On the bright side, you can use it from time to time for small script when you want to work fast and you are the only one to use it. That's the way I use it.
For your problem, you can use it, with the appropriate names and the correct syntax, it's up to you.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrices and Arrays 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!