## Delimate Table and Rewrite it

### Seum Bin Rahman (view profile)

on 13 Oct 2019
Latest activity Commented on by Peter Perkins

on 15 Oct 2019

### Walter Roberson (view profile)

I have a Table. One of the colums has multiple strings seperated by comma. The table is as follows;
MODELS PROBLEMS
_______________________ ____________________________________
I wish to delimate column "PROBLEMS" and save it back to another table which will have three columns, POBLEMS1, PROBLEMS2, PROBLEMS3.
The code is as follows
r=0;
raw_problem=raw.Expert_Found_Problems;
P=height(raw);
for i=1:1:P
PROBLEMS=raw_problem{i,1};
C = strsplit(PROBLEMS,',');
r=r+1
T(r,:)=table(C)
end
T=T
Error is as follows
Error using t3 (line 15)
Subscripted assignment dimension mismatch for table variable 'C'.
Excel file is also attached

### Tags ### Walter Roberson (view profile)

on 13 Oct 2019

table() applied to the results of strsplit is probably giving you a table with one variable and three rows.
You need to take special steps when the input is a vector because there is an ambiguity over whether to create a table with one row and several variables, or a table with several rows and one variable.
table(C{1},C{2},C{3}, 'VariableNames', {'Problem1', 'Problem2', 'Problem3'})

Seum Bin Rahman

### Seum Bin Rahman (view profile)

on 13 Oct 2019
My God it worked!! I dont understand the first two lines. But its okey. You may explain if you are free
Walter Roberson

### Walter Roberson (view profile)

on 13 Oct 2019
In MATLAB, there is no direct (and readable) way to call a function and immediately select a subset of the result. It would be nice if it were permitted to do something like,
[V{:}, {'','',''}](1:3) %not actually permitted
but MATLAB does not provide for that. It does, though, make it possible to call a function on a computed result, and for the function to take the subset.
Thus,
will be passed a 1 x something cell array with a varying number of elements in it, from 0 to 3. The {:} part expands the cell into individual arguments of the [] function it is inside; that will expand to 0, 1, 2, or 3 arguments. Then the cell with 3 empty strings is appended through the [] operator, which gives you a cell result with 3, 4, 5, or 6 elements, with the last 3 being empty in each case. Then First3 is called on that, returning the first 3 of the elements. So {} the empty cell would become {'' '' ''} and {'one'} would become {'one' '' ''} and {'one' 'two'} would become {'one' 'two' ''} and {'one' 'two' 'three'} would stay {'one' 'two' 'three'}.
The raw_problem = raw.Expert_Found_Problems line is going to give you a cell array column vector each containing a character vector. The C = regexp(raw_problem, ',', 'split') line is going to give you a cell array the same size, with each entry being a cell array that has as many entries as there are comma deliminated parts. Like,
{
}
The arrayfun() is going to process each of those rows, so it is going to pass PAD3 {'CHARGING' 'keypad lock' 'DEAD'} first, then {'DEAD' 'AUTO on off'} then {'KEYPAD'} . As indicated above, that will convert to
{
}
Notice that all of the entries now contain exactly the same number of columns.
Now that they all contain the same number of columns, the line
C = vertcat(C{:});
converts that to
{