How to put some string in a variable?

Hi everyone ,
i have a question about this code :
function fonction_graphs_1(handles)
val = get(handles.graph,'Value');
str = get(handles.graph,'String');
switch str{val};
case 'Electrique'
set (handles.graph_1,'Enable','on');
nameList = {'modele_'};
for iIndex = 1:10
Field = sprintf('%s%d', nameList{1},iIndex);
if findobj('Tag',Field,'Enable','on')
H = handles.(Field);
String = get(H, 'String');
Value = get(H, 'Value');
fichier = String{Value};
set (handles.graph_1,'String',{'', fichier },'value',1);
end
end
i would like than " fichier " become a variables which can add all the thing i select, These are "String" and if i put " fichier " in this code :
set (handles.graph_1,'String',{'', fichier },'value',1);
All the string will be show ?
Is it possible ?
Thank you

4 comentarios

Geoff Hayes
Geoff Hayes el 5 de Ag. de 2014
Hugo - where in the code would you update fichier to be the list of all "things" that can be selected? In the above function or elsewhere? Is handles.graph_1 a list box which will contain all of these selections?
Hugo
Hugo el 5 de Ag. de 2014
Editada: Hugo el 5 de Ag. de 2014
Yes sorry , graph_1 can contain : ' ' , ' Electric' and 'Thermic'
Geoff Hayes
Geoff Hayes el 5 de Ag. de 2014
And where does fichier get set with the selected items?
Hugo
Hugo el 5 de Ag. de 2014
Editada: Hugo el 5 de Ag. de 2014
modele_1 to 10 , graph and graph_1 are Popupmenus
fichier = String{Value};
set (handles.graph_1,'String',{'', fichier },'value',1);

Iniciar sesión para comentar.

Respuestas (1)

Geoff Hayes
Geoff Hayes el 7 de Ag. de 2014
Hugo - if you just want to update fichier at each iteration and then add to the list after, then you could do something like this
fichier = {''};
for iIndex = 1:10
Field = sprintf('%s%d', nameList{1},iIndex);
if findobj('Tag',Field,'Enable','on')
H = handles.(Field);
String = get(H, 'String');
Value = get(H, 'Value');
fichier = [fichier ; String{Value}];
end
end
% now update the widget
set (handles.graph_1,'String',fichier,'value',1);
Try the above and see what happens!

4 comentarios

Hugo
Hugo el 7 de Ag. de 2014
Editada: Hugo el 7 de Ag. de 2014
It's ok now i got a little problem : i could have 10 different choice about the motor , i don't kno how to check the different name , ( ME_1 to 10 ) Cause i can choose the same motor for some time and i want to put the name only one time , there are in a TABLE
Since fichier is a cell array, do something like the following to check to see if the motor is already in the list
if isempty(find(strcmpi(fishier, String{Value})))
fichier = [fichier ; String{Value}];
end
For example,
fichier = {'' ; 'Electric' ; 'Thermic' ; 'NA' ; 'Other'}
find(strcmpi(fichier,'Electric'))
ans =
2
find(strcmpi(fichier,'Electric2'))
ans =
Empty matrix: 0-by-1
If the string is in the cell array, then find returns the index of that string in the cell array. Else if the string is not in the list (as in the second example) then an empty matrix is returned.
Hugo
Hugo el 8 de Ag. de 2014
Editada: Hugo el 8 de Ag. de 2014
nameList = {'modele_'};
for iIndex = 1:10
Field = sprintf('%s%d', nameList{1},iIndex);
if findobj('Tag',Field,'Enable','on')
H = handles.(Field);
String = get(H, 'String');
Value = get(H, 'Value');
fichier = String{Value} ;
if strncmp (fichier ,'ME_',3)
tableau{j} = fichier;
j = j+1;
end
end
end
tableau
for i=1:length(tableau)
for j=i+1:length(tableau)
if strcmp(tableau{i},tableau{j})
tableau{j}= -1;
end
end
end
tableau
set (handles.graph_1,'String',tableau,'value',1);
i would like to set only the String ME_X , and don't put -1
( -1 is when a Motor is 2 time or more show )
exemple :
tableau =
'ME_1.m' 'ME_1.m' 'ME_2.m' 'ME_1.m'
tableau =
'ME_1.m' [-1] 'ME_2.m' [-1]
They're put in a TABLE
Hugo - I'm not really clear on what you want. You state that i would like to set only the String ME_X , and don't put -1. But you have written code to put the -1. Why? Why not use the example I showed in the previous comment
if isempty(find(strcmpi(fishier, String{Value})))
fichier = [fichier ; String{Value}];
end

Iniciar sesión para comentar.

Categorías

Más información sobre Startup and Shutdown en Centro de ayuda y File Exchange.

Preguntada:

el 5 de Ag. de 2014

Comentada:

el 8 de Ag. de 2014

Community Treasure Hunt

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

Start Hunting!

Translated by