Your whole process of adding a new column and detecting your excess threshold is overly complicated. There is certainly never any need to convert to a matrix.
Table = array2table(randi([0 150], 69, 4), 'VariableNames', {'something', 'W', 'X', 'N'})
colnames = Table.Properties.VariableNames(2:4);
warnings = rowfun(@(val) {strjoin(colnames(val > 100), ',')}, ...
Table, ...
'InputVariables', 2:4, ...
'OutputVariableNames', 'Warning', ...
'SeparateInputs', false);
Table = [warnings, Table]
I've separated the rowfun call onto several lines for readability.
In the above, I call rowfun to process each row one at a time. 'InputVariables' tells it which columns to process (2 to 4), 'OutputVariableNames' tells it which name to give to the output column, 'SeparateInputs', false tells it to keep the values of columns 2:4 together as a vector (easier to process).
The processing function I'm giving to rowfun is an anonymous function which one input val. That val will receive columns 2:4 of each row as a vector. I compare the values of this vector to your threshold. This gives me a logical vector that is used to filter the columns names. I then join these filtered column names together into one char array with strjoin and finally wrap that into a cell array so that it can be put into a table column.
P.S: Please give a better name to your table and to columns M, X, N. Something that actually explain what's in there. Yearlysomething would be a better name for the table, whatever that something is.
Best Answer