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 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
for example a='Datat.signal.EMG'; data=(a);
2 commentaires
Guillaume
le 12 Juil 2018
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.
Réponse acceptée
Guillaume
le 12 Juil 2018
Modifié(e) : Guillaume
le 12 Juil 2018
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 commentaires
Plus de réponses (0)
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!