hi, everybody. my question is how can I use a string for calling a structure . for example my string is "Data. signal.EMG" and I want data=Data.signal.EMG.

1 次查看(过去 30 天)
for example a='Datat.signal.EMG'; data=(a);
  2 个评论
Guillaume
Guillaume 2018-7-12
Something has gone very wrong if you want to do that. Accessing variable dynamically is always bad practice. Can you rewind a bit and explain how you came to be in this situation? We'll tell you how to do it properly.
ali jafari
ali jafari 2018-7-12
编辑:ali jafari 2018-7-12
thank you. actually, I collected data(EMG signal) from 10 subjects for wrist movements (Extension, Flexion,..). i save this data in structures (subject01, subject02,....subject10).each structure has some fields. signals save in field subject01.Data.EMG.Extension. I design a GUI in Matlab. GUI has some options who you can select a subject number and movement name and.... .when you select this option in GUI this names (subject01, Flexion,..) are the string. I want to Strcat all them and save in variable then plot signal. in fact, I have string who is data address. I want this string to be structure fields address. forgive me for my terrible English. this is my GUI picture.

请先登录,再进行评论。

采纳的回答

Guillaume
Guillaume 2018-7-12
编辑:Guillaume 2018-7-12
subject01, subject02,....subject10
Here you go, that's where you've gone wrong. Never number variables. It's a clear indication that your design is wrong. Instead of numbered variables you should use a container to hold all of these variables. In your case, instead of individual scalar structures subject01, subject02,....subject10, you should have one single structure array subject(1), subject(2), ... subject(10). Then it's a simple matter of indexing that array to get any of this structure.
The best solution would be to change the way you created these structures in the first place. If you show us the code you've used, we'll correct it. Failing that:
subject = [subject01, subject02, ..., subject10]; %fill the ... yourself
selectednumber = 4; %subject number selected by the user in your GUI
selectedsubject = subject(selectednumber); %get subject selected by the user

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Modeling 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by