How to read the value of a variable that has dots in between
3 ビュー (過去 30 日間)
古いコメントを表示
Hello
I have a variable name with dots in between xxx.yyy.zzz and the variable has a value assigned to it.
How can I read that value and assign to another variable. I tried to read the variable as a string but then how can I know the value assigned to it.
Please help.
2 件のコメント
Mathieu NOE
2021 年 5 月 21 日
hello
do you mean xxx.yyy.zzz contains numerical data and that's what you want to retrieve ?
回答 (1 件)
Jan
2021 年 5 月 21 日
What does "I have a variable name" mean? Where does this variable exist? It is not a legal Matlab symbol so you cannot create such a variable without evil hacking methods.
Modern Matlab versions prevent the creation of such variables through loading them from ugly MAT files.
Maybe you are talking of an external text file and "xxx.yyy.zzz" is the title of a column or row. Or you mean a struct as:
xxx.yyy.zzz = 17
2 件のコメント
Jan
2021 年 5 月 21 日
".dat" is not a fixed file format. So it is not clear how you import it at all. If you store the variables and the names as fields of a struct, the inport should work directly. The result would e.g. be:
ImportedData(1).Name = 'xxx.yyy.zzz';
ImportedData(1).Value = [1,2,3,4,5];
You can modify the import also such that dots are replaced by underscores. Then this is possible:
ImportedData.xxx_yyy_zzz = [1,2,3,4,5];
Currently we do not have enough information to suggest a specific method and we do not know the format of your ".dat" files.
参考
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!