Combining string cell arrays to put in UITable

4 visualizzazioni (ultimi 30 giorni)
Happy Thanksgiving!
I am trying to create a table that stores notifications from our system by concatenating three strings together into a 1X3 Cell array. While this works fine if I'm trying to replace data in a UITable, it doesn't work if I want to append data. Previously in my project I used the get() and set() method to grab append data into the table, as shown below(All data is of type 'double'):
Final = [joints(2), joints(3),joints(4),mag]; %The HR, Ambient, Skin temp and Resultant g force in one line for
ED = get(app.UITable, 'Data'); %collecting data currently in table
new = [ED; Final]; %concatenating new data in table with new sensor data
set(app.UITable, 'Data', new); %putting 'new' data back into table
I am trying to recreate this method using strings but I keep getting an error. Here is that code below:
z = sprintf('%s has suffered a large hit! Please screen for concussion',per);
d = msgbox(z);
t = datetime('now');
tim = datestr(t);
g = num2str(grat,2);
together = {z, tim, g} %creates 1X3 cell array
DED = get(app.UITable_3, 'Data') %gets '[]' of type double
ged= num2cell(DED) %Tried converting '[]' to cell type
new = {ged, together}%Would like to 2x3 cell array, instead gets 1x2 cell array
set(app.UITable_3,'Data', new) %put data back
Error:
Error using matlab.ui.control.Table/set
Error setting property 'Data' of class 'Table':
Values within a cell array must be numeric, logical, or char
Error in Player_View2/alert (line 91)
set(app.UITable_3,'Data', new)
Error in Player_View2/SwitchValueChanged (line 185)
alert(app, app.P1,mag)
Error using matlab.ui.control.internal.controller.ComponentController/executeUserCallback (line 378)
Error while evaluating Switch PrivateValueChangedFcn.
Thanks in advance

Risposta accettata

Jesus Sanchez
Jesus Sanchez il 28 Nov 2019
Values within a cell array must be numeric, logical, or char
Well, your answer is there. In the following line, you are declaring the value as a cell array:
new = {ged, together}
Therefore, new is of cell type, not a numeric, logical or char. I would try to convert it to those values.
Otherwise, you might want to operate always in numeric format, intead of cells. A quickly and not tested solution:
z = sprintf('%s has suffered a large hit! Please screen for concussion',per);
d = msgbox(z);
t = datetime('now');
tim = datestr(t);
g = num2str(grat,2);
together = [z, tim, g] %creates 1X3 vector
DED = get(app.UITable_3, 'Data') %gets data from table
%ged= num2cell(DED) You dont need this, format of DED should be numeric now
new = [DED; together] %Like this, it puts together below DED.
set(app.UITable_3,'Data', new) %put data back
It might be possible that the first iteration, as there is no data in the table, gives you an error. If that is the case, try using below DED:
if isempty(DED) % Check if empty array
new = [together];
else
new = [DED; together] %Like this, it puts together below DED.
end
set(app.UITable_3,'Data', new) %put data back

Più risposte (0)

Prodotti


Release

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by