Numeric column, text column, uitable using guide
1 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
回答(1 个)
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];
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Characters and Strings 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!