Storing a multiple data into table GUI using a pushbutton and a checkbutton

Hello,
I am developing a GUI in MATLAB using GUIDE and I have some pre calculated numeric values A, B and C (there are more) which I converted to cells using num2cell in order to store them in a table.
Now I want to store these calculated values in a table (in columns AA, BB and CC) in a table named Table_results by clicking on a Pushbutton with previously checked/unchecked checkbutton (this is to check wheather to use or not to use these pre calculated data).
I am struggling with how to put them all in a table, since only the last dataset C is stored in a table Table_results:
I tried something like this which, if I use them one at a time, gives me the value (AA, BB or CC) stored in a Table_results.
But when I use this code below, the last value CC is overriding the previous two:
set(handles.Results_table, 'Data', A);
set(handles.Results_table, 'Data', B);
set(handles.Results_table, 'Data', C);
set(handles.Results_table,'ColumnName',{'AA'}) %%this is in order to name my columns AA, BB and CC
set(handles.Results_table,'ColumnName',{'BB'})
set(handles.Results_table,'ColumnName',{'CC'})
I have more data to implement in this same manner, so in the end I am looking to write a code that enables me to store only the data i selected in checkbutton and display them in a Table results table when I click on a Pushbutton.
Any help would be greatly appreciated.
Thanks in advance!

9 comentarios

Well, you are telling it to override the previous ones by just setting 'Data' to something different.
Just get the whole 'Data' out of the table, update it (with numeric data if that is what you have) and then set it again.
Hi Adam,
I know that I am overriding it, but I am not sure on how to correct this issue. I cant just remove 'Data' out of the table, since an error will pop up.
How to do that correctly?
Thanks!
data = get( handles.Results_table, 'Data' );
data( 2,4 ) = 7;
data( :,3 ) = B;
set( handles.Results_table, 'Data' );
etc
I have tried this:
data = get( handles.Results_table, 'Data' );
data( :,1 ) = A;
data( :,2 ) = B;
data( :,3 ) = C;
set( handles.Results_table, 'Data');
But it gives me an error:
Subscripted assignment dimension mismatch.
data( :,1 ) = A;
My A, B and C values are (49x1 double)
What can I do now? I am stuck.
What size is data?
The size of A, B and C data is (49x1 double).
I converted them to cell to use it in a table using num2cell function.
What about the variable you call data though. What size is that? And if your data is numeric then store it in a numeric array and store that as 'Data' in the table. Don't use a cell array if you don't need to.
A, B and C are my results that I calculated from the previous code I wrote.
So that is what I want to put in a table.
The results are stored in a nx1 format (49x1 that I mentioned is just from testing one set of data).
I used cells as I thought that would be suitable for handling in table. But it is not neccesary if you have a better idea.
I managed to make it work. The problem was to move the functions that I made above the problematic code and after joining the data together + removing this line of code:
data = get( handles.Results_table, 'Data' );
I was able to get it to work.
Thanks for your help!

Iniciar sesión para comentar.

Respuestas (1)

When you are using set(handles.Results_table,'ColumnName',{'CC'}) its storing any data in the same address that is handles.Results_table. You can use setappdata and getappdata. By this you can share data to different GUI's and it is pretty powerful. If you want to make your data global use setappdata(0,..... ) . Always store with different names. If you are using same name and same address it's going to overwrite your previous data. That's how set and get works. Hope this helps.

2 comentarios

Thanks you for your answer regarding globals and their callbacks, I appreciate it. But I have another issue now.
When I click on Pushbutton to calculate values AA,BB separately or together, I am not sure how to enable/disable them and display in table Results_table properly.
My following code for this is:
AA = get(handles.A,'Value');
if AA == 1
%%Perform function. Here I calculate the function AA
AA = num2cell(AA);
data(:,1) = AA;
data1=data(:,1);
set(handles.Results_table,'Data', data1);
set(handles.Results_table,'ColumnName',{'AA'});
else
end
BB = get(handles.B,'Value');
if BB== 1
%%Perform function. Here I calculate the function BB%%
BB = num2cell(BB);
data(:,2) = BB;
data1=data(:,2);
set(handles.Results_table,'Data', data1);
set(handles.Results_table,'ColumnName',{'BB'});
else
end
Now, when I press Pushbutton in order to execute this functions (weather thaey are previously checked/unchecked with checkbutton) I am not getting a desired result stored in table Results_table with proper column names.
What I want in the end is depending on which checkbutton I select, after pressing the Pushbutton I want to store and display the selected results in table Results_table with appropriate column names.
What am I doing wrong?
Thanks!
@Mario: Is this the same question as here?

Iniciar sesión para comentar.

Categorías

Más información sobre Historical Contests en Centro de ayuda y File Exchange.

Preguntada:

el 2 de Ag. de 2017

Comentada:

Jan
el 5 de Ag. de 2017

Community Treasure Hunt

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

Start Hunting!

Translated by