UItable(app.UITable2) filters it's with respect to Name (app.Filter_Name). But the table does not update display data of the table.

1 次查看(过去 30 天)
app.Filter_Name = app.NAMEEditField.Value;
numRows = size(app.UITable2.Data,1);
r = 1;
for i = 1:numRows
if strcmp(app.UITable2.Data{i,1}, app.Filter_Name) %app.UITable2.Data{i,1} ~= app.Filter_Name
app.RowstoTake(r,1) = i; %app.RowstoTake(1,r)= i;
r = r + 1;
end
end
app.UITable2.Data = app.UITable2.Data{app.RowstoTake, :};
The following error arises, "Unable to concatenate the table variables 'Name' and 'Number', because their types are cell and double." Please advise.

采纳的回答

Walter Roberson
Walter Roberson 2021-8-16
app.UITable2.Data = app.UITable2.Data{app.RowstoTake, :};
Remember that {} requests the content of a table, as if you had done [Data{:,1}, Data{:,2}, Data{:,3} etc] . But if the variables are not compatible datatypes then that would be a problem.
Now... suppose that the table variables just happened to be compatible datatypes. For example if you had a table that was a mix of string and numeric, then {:,:} indexing can convert everything to string, giving a string array, and that would be legal. So imagine that happened, that it happened to work out on the right side, maybe giving a string array.
Now look on the left side of the assignment. app.UITable.Data is to be assigned... that string array then? Is it to be turned into whatever datatype worked out as being acceptable to convert everything to?? Even though now it is a table datatype ?
I would suggest to you that you should instead be using
app.UITable2.Data = app.UITable2.Data(app.RowstoTake, :);
This would be a matter of selecting rows from the table, returning a table object, suitable for storing into a place that is currently a table object.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

产品


版本

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by