How to read the value of a variable that has dots in between

3 ビュー (過去 30 日間)
Venkatraman Nagarajan
Venkatraman Nagarajan 2021 年 5 月 21 日
コメント済み: Jan 2021 年 5 月 21 日
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
Mathieu NOE 2021 年 5 月 21 日
hello
do you mean xxx.yyy.zzz contains numerical data and that's what you want to retrieve ?
Venkatraman Nagarajan
Venkatraman Nagarajan 2021 年 5 月 21 日
Yes. You are correct. I want to read the data stored in that variable. The data sometimes a numerical data and sometimes it's a string value like 'OK', 'NOT_OK', 'TRUE' and 'FALSE'.

サインインしてコメントする。

回答 (1 件)

Jan
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 件のコメント
Venkatraman Nagarajan
Venkatraman Nagarajan 2021 年 5 月 21 日
Hi Jan
Yes, the variable is from an external file. It is a .dat (measurement file). It has the recordings of all the variables that we measure during the test. And one of those variables which we considered for measurement has this name (with dots). So, I wanted to read the value of this variable from the .dat file during post processing to verify the functionality of the component. Nevertheless, we could read the values of all the variables that doesn't have this format (with dots), but this one.
Jan
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.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeVariables についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by