|
|||||||
|
|
|
![]() |
|
|
Strumenti |
|
|
#1 |
|
Senior Member
Iscritto dal: Jun 2003
Città: Napoli prov
Messaggi: 3089
|
[MATLAB] Ciclo for su handles oggetti gui
Ciao a tutti!
Ho creato una gui in matlab che ha vari oggetti tra cui 25 testi editabili che hanno un numero progressivo (es: handles.Rp1, handles.Rp2, ...., handles.Rp25). Dovendo fare delle operazioni sulla gui che coinvolgono tutti questi 25 testi editabili (nel campo string e nel campo value) volevo evitare di dover settare i singoli campi per 25 volte (per un totale quindi di 50 linee di codice praticamente uguali a meno del numero dell'handles). Avevo pensato di fare un ciclo for del tipo: for i=1:25 var=strcat('handles.Rp',i); set (var,'String','valore che mi serve) set (var,'Value',valore che mi serve) guidata(h0beject, handles) end Con il sistema che ho scritto su var assume correttamente i valori handles.Rp1, handles.Rp2, ... etc . Il problema è che così facendo non me l'accetta più nella funzione set dicendomi che var deve essere un handles, mentre con lo strcat è visto come una stringa: come posso fare a rendere la stringa l'handles dell'oggetto corrispondente? C'è una soluzione vero? Non devo essere costretto a scrivere 50 orribili righe di codice pressochè identiche, vero??? Grazie mille a tutti!
__________________
Thermaltake Armor VA8000SWA**Corsair CMPSU-620HX**Intel Core 2 Quad Q9450 **Asus P5Q Deluxe**Corsair Dominator 2x2GB PC8500 1066Mhz-555 XMS2**Sapphire Vapor-X HD7970 GHz Edition 3GB GDDR5**Samsung SSD 830 256GB**WD Caviar 1TB SATA**Creative X-Fi Elite Pro **Pioneer DVR-215D**Altec Lansing FX6021**Crossover 2720MDP**Logitech diNovo Cordless Desktop**Cooler Master Storm Sentinel Advance on Razer eXactMat |
|
|
|
|
|
#2 |
|
Senior Member
Iscritto dal: Jun 2003
Città: Napoli prov
Messaggi: 3089
|
Per far capire meglio lo scempio che c'è nel mio codice ne metto un piccolo frammento che è più che esplicativo :d
Codice:
set(handles.thr0,'String',20) set(handles.thr0,'Value',20) set(handles.thr1,'String',20) set(handles.thr1,'Value',20) set(handles.thr2,'String',20) set(handles.thr2,'Value',20) set(handles.thr3,'String',20) set(handles.thr3,'Value',20) set(handles.thr4,'String',20) set(handles.thr4,'Value',20) set(handles.thr5,'String',20) set(handles.thr5,'Value',20) set(handles.thr6,'String',20) set(handles.thr6,'Value',20) set(handles.thr7,'String',20) set(handles.thr7,'Value',20) set(handles.thr8,'String',20) set(handles.thr8,'Value',20) set(handles.thr9,'String',20) set(handles.thr9,'Value',20) set(handles.thr10,'String',20) set(handles.thr10,'Value',20) Quale sarà mai sta benedetta funzione?
__________________
Thermaltake Armor VA8000SWA**Corsair CMPSU-620HX**Intel Core 2 Quad Q9450 **Asus P5Q Deluxe**Corsair Dominator 2x2GB PC8500 1066Mhz-555 XMS2**Sapphire Vapor-X HD7970 GHz Edition 3GB GDDR5**Samsung SSD 830 256GB**WD Caviar 1TB SATA**Creative X-Fi Elite Pro **Pioneer DVR-215D**Altec Lansing FX6021**Crossover 2720MDP**Logitech diNovo Cordless Desktop**Cooler Master Storm Sentinel Advance on Razer eXactMat |
|
|
|
|
|
#3 |
|
Senior Member
Iscritto dal: Jun 2003
Città: Napoli prov
Messaggi: 3089
|
Ho risolto il problema!
Scrivo anche qui la soluzione così che magari può essere utile in futuro a qualcuno: Codice:
for i=0:24
var=handles.(['thr' num2str(i)]);
set (var,'String',20);
set (var,'Value',20);
end
Ciao!
__________________
Thermaltake Armor VA8000SWA**Corsair CMPSU-620HX**Intel Core 2 Quad Q9450 **Asus P5Q Deluxe**Corsair Dominator 2x2GB PC8500 1066Mhz-555 XMS2**Sapphire Vapor-X HD7970 GHz Edition 3GB GDDR5**Samsung SSD 830 256GB**WD Caviar 1TB SATA**Creative X-Fi Elite Pro **Pioneer DVR-215D**Altec Lansing FX6021**Crossover 2720MDP**Logitech diNovo Cordless Desktop**Cooler Master Storm Sentinel Advance on Razer eXactMat |
|
|
|
|
| Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 17:31.



















