How to make a dynamic array in GUI?

1 vue (au cours des 30 derniers jours)
Lin LIU
Lin LIU le 19 Juin 2016
Commenté : Lin LIU le 20 Juin 2016
Hi fellows,
I am trying to make dynamic arrays in GUI, where the user can keep adding new elements. It is like the user does not know the exact number of total elements at the beginning. So the user would just add new element to it until he/she is satisfied.
For example, I am going to add some new items to an array with their names. Here is what I suppose, under a pop-up menu callback:
str = get(hObject, 'String');
val = get(hObject,'Value');
handles.itemnames = {};
switch str{val};
case 'A'
???????
case 'B'
???????
case 'C'
???????
end
guidata(hObject,handles)
So my problem is: what I should write for "???????" to achieve that if the user choose 'A' from the pop-up menu and click a 'done' button, the name 'A1' will be stored in the first position of handles.itemnames array. Then if the user choose 'B', the name 'B1' will be stored in that same array at the second position. And then if the user choose another 'A', the name 'A2' will be stored in that array at the third position. The process can go on and on until the user is satisfied. The names are generated automatically with unique index number, from A1/B1/C1 to An/Bn/Cn.
Any answer or advice would be much appreciated.
Regards,
Lin
  4 commentaires
Lin LIU
Lin LIU le 20 Juin 2016
Geoff: Thank you for your attention and yes, the itemnames will go like {'A1','A2','B1','C1'...} as the user keeps adding new elements. I think there would be no limit to the number of strings. Stephen's advice is revealing. I will try if I can alter my code and make my problem clearer. Thank you!
Lin LIU
Lin LIU le 20 Juin 2016
Stephen: Thank you for your valuable advice! I have been thinking about it and my original code is indeed bad. I will try to improve my code referring to your link. Thank you very much!

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Variables dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by