Azzera filtri
Azzera filtri

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 visualizzazione (ultimi 30 giorni)
for example a='Datat.signal.EMG'; data=(a);
  2 Commenti
Guillaume
Guillaume il 12 Lug 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.
ali jafari
ali jafari il 12 Lug 2018
Modificato: ali jafari il 12 Lug 2018
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.

Accedi per commentare.

Risposta accettata

Guillaume
Guillaume il 12 Lug 2018
Modificato: Guillaume il 12 Lug 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

Più risposte (0)

Categorie

Scopri di più su Modeling in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by