필터 지우기
필터 지우기

Numeric column, text column, uitable using guide

조회 수: 1 (최근 30일)
Mary Caroline
Mary Caroline 2014년 2월 20일
댓글: Mary Caroline 2014년 2월 20일
Hello everyone. I have spend the last couple of days on this issue and cannot figure it out. I have a Gui which reads some data and plot them. The user can select some specific points and modify them. I want to keep track of the changes made by storing them in a table. So far everything is fine. I have my array of numbers, they appear normally in my table. The problem is that I want to indicate the source of the change as well. In other words, my first 4 columns will be numeric values and the last one will be a text value. The options of putting the data by hand is not possible as I want something automatic.
I understood that this last variable needs to be a cell but I just can't figure out how to transfer my array ( for example: 'combustion' 'load'..) into a cell array.
Here is the part of my code that is of interest:
%pick the values which is initialised at the opening of the GUI.
conditions_changed=evalin('base','conditions_changed');
&Populates with the new value
conditions_changed=[conditions_changed; initial_values];
%stores it
assignin('base','conditions_changed',conditions_changed);
origin_change=evalin('base','origin_change');
origin_change=[origin_change; 'c'];
assignin('base','origin_change',origin_change);
set(handles.uitable1,'Data', [conditions_changed origin_change]);
I have tried replacing the [] with () and using the following formulation origin_change=cellstr(char(origin_change, 'c')) but I get an error on the CAT Format.
Last detail: I made sure that my column format are set to 'Let Matalb choose'.
Thanks

답변 (1개)

Iain
Iain 2014년 2월 20일
This is how I'd do it:
Table_o_values = [1 561 1;
2 156 2;
4 951 3];
In the 3rd column, I'd use an enumeration. Eg. 1 = Not known, 2, = load, 3 = combustion, etc.
enum = {'NK','ld','cb'};
To build the cell array
left_bit = num2cell(Table_of_values(:,1:2));
right_bit{:,1} = enum{Table_of_values(:,3));
concatenated_cell_array = [left_bit right_bit];
  댓글 수: 1
Mary Caroline
Mary Caroline 2014년 2월 20일
Thanks for your quick answer. I reproduced and adapted what your wrote above. The cell array is correctly created. I checked its type, and it is indeed a cell. However when I assign the value to the table ( set(handles.uitable1,'Data', concatenated_cell_array); ) I get the following error, which I don't understand:
??? Error using ==> set
Data must be a numeric, logical, or cell array
Error in ==>
interface_cmb>pushbutton_update_Callback at 902
set(handles.uitable1,'Data', 'concatenated_cell_array');
Error in ==> gui_mainfcn at 96
feval(varargin{:});
Error in ==> interface_cmb_integration_try1 at 43
gui_mainfcn(gui_State, varargin{:});
Error in ==>
@(hObject,eventdata)interface_cmb('pushbutton_update_Callback',hObject,eventdata,guidata(hObject))
??? Error while evaluating uicontrol Callback

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by