Referring to variables with concatenated strings

29 ビュー (過去 30 日間)
Ross Boland
Ross Boland 2015 年 4 月 2 日
編集済み: Stephen23 2019 年 6 月 19 日
I want to run a loop that will apply the same functions to many sets of data. For example the data names are named by putting the sensor type first, then what is been recorded, then what recording it is, for example
accel_cycle_1 gyro_run_4
In each variable there is 3 columns of data. I can concatenate the sensor type, data type and the number. I then want to refer to specific columns in the variables with a function I made for each concatenated string, but matlab assigns values to the letter of the string rather than referring to variable of that name. Is it possible to do this? Thanks
  1 件のコメント
Stephen23
Stephen23 2015 年 4 月 2 日
Use indices instead of creating variable names dynamically. Read the answers to know why!

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

採用された回答

James Tursa
James Tursa 2015 年 4 月 2 日
Yes it is possible to do this using eval, but please do not do this! There are much better ways to organize your data using cell or struct arrays. E.g., see these links:

その他の回答 (2 件)

Stephen23
Stephen23 2015 年 4 月 2 日
編集済み: Stephen23 2019 年 6 月 19 日
  1 件のコメント
Ross Boland
Ross Boland 2015 年 4 月 2 日
That's very helpful, Thanks

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


Matt J
Matt J 2015 年 4 月 2 日
編集済み: Matt J 2015 年 4 月 2 日
You should not be using parts of a variable's name to index data. You should be using indices to index data. E.g., instead of
A1=5;
A2=10;
you should be doing
A(1)=5;
A(2)=10;
or other indexing types like cell array indexing.

カテゴリ

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