Problem with Cell Arrays in GUIDE
Mostrar comentarios más antiguos
I am attempting to fill a cell array as follows: CellArray(1,50)={zeros(M,N)} With M being popupmenu options and N being listbox options.
so far I have this code which does work to a certain extent. It takes listbox options and popupmenu options and stores them into array. popupmenu options are columns and listbox options are rows. I am attempting to use a for loop to store the currently selected items into my cell array, Z:
R = get(handles.popupmenu1,'val');
%listbox accepts multiple selections*
C = get(handles.listbox1,'val');
A = zeros(length(get(handles.popupmenu1,'string')),length(get(handles.listbox1,'string')));
I = sub2ind(size(A),[R repmat(R,1,length(C))],[1 C]);
Z = cell(1,50);
for i = 1: 50
Z(:) = {I}
end
The only problem is that it saves all of the listbox options and all of the popupmenu options instead of just the currently selected items. But it does store the array A into the 1 x 50 cell array Z so I guess its a start. So the question is how would i need to modify this code in order to into my 1 by 50 cell array?
Here is what the output looks like:
Z =
Columns 1 through 7
[1x7 double] [1x7 double] [1x7 double] [1x7 double] [1x7 double] [1x7 double] [1x7 double]
Columns 8 through 14
[1x7 double] [1x7 double] [1x7 double] [1x7 double] [1x7 double] [1x7 double] [1x7 double]
Columns 15 through 21
[1x7 double] [1x7 double] [1x7 double] [1x7 double] [1x7 double] [1x7 double] [1x7 double]
Columns 22 through 28
[1x7 double] [1x7 double] [1x7 double] [1x7 double] [1x7 double] [1x7 double] [1x7 double]
Columns 29 through 35
[1x7 double] [1x7 double] [1x7 double] [1x7 double] [1x7 double] [1x7 double] [1x7 double]
Columns 36 through 42
[1x7 double] [1x7 double] [1x7 double] [1x7 double] [1x7 double] [1x7 double] [1x7 double]
Columns 43 through 49
[1x7 double] [1x7 double] [1x7 double] [1x7 double] [1x7 double] [1x7 double] [1x7 double]
Column 50
[1x7 double]
Respuesta aceptada
Más respuestas (2)
Fangjun Jiang
el 30 de Jun. de 2011
I must say I didn't try to understand all of your discussion. From all of your three questions, may I suggest a different approach? If you put a uitable in the GUI and let the user fill the data, would it be easier? Every time the user fill the data and then press a button, you can save the data. I understand that the user may need to do this 50 times, which is not easy. But in your current way, the user also need to do 50 times, right? It's probably not a good UI. I can't imaging any user doing it 50 times.
Just a thought! Below is a sample code.
h=uitable('Data',zeros(10),'ColumnEditable',true(1,10),'ColumnWidth',repmat({25},1,10))
Fill a few cells and then run
Data=get(h,'Data')
1 comentario
B_Richardson
el 30 de Jun. de 2011
Fangjun Jiang
el 30 de Jun. de 2011
Should the line inside the for-loop be this ?
Z(i)={I};
And questions: what is the typical value of get(handles.popupmenu1,'string') and get(handles.listbox1,'string')?
6 comentarios
B_Richardson
el 30 de Jun. de 2011
B_Richardson
el 30 de Jun. de 2011
B_Richardson
el 30 de Jun. de 2011
B_Richardson
el 30 de Jun. de 2011
Matt Fig
el 30 de Jun. de 2011
O.k., so now it looks like there are multiple confusions. You do or do not want all 50 elements of the cell to be filled with the same A? As I understand it now, you want to have a different A saved in the cell each time the user selects from the popup, for a total of 50 different saves. Is that correct?
B_Richardson
el 30 de Jun. de 2011
Categorías
Más información sobre Matrix Indexing en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!