The error we see is happening in the split function because not every string in string(FEC_fb2(1:end-1)) has the same number of commas, referred to as "matches" in the error message.
Hopefully this example demonstrates the issue a little more clearly.
>> split(["a,b";"c,d"],",")
ans =
2×2 string array
"a" "b"
"c" "d"
>> split(["a";"c,d"],",")
Error using split
Element 2 of the text contains 1 matches while the previous elements have 0. All
elements must contain the same number of matches.
You can get around this issue by calling split separately on each string and assigning the results to a cell array, which allows elements of different lengths.
strs = ["a";"c,d"];
strsSplit = cell(1,numel(strs));
for i = 1:numel(strs)
strsSplit{i} = split(strs(i),",");
end
strsSplit
which outputs
strsSplit =
1×2 cell array
{["a"]} {2×1 string}
>> strsSplit{2}
ans =
2×1 string array
"c"
"d"
Alternatively, you can use arrayfun.
>> arrayfun(@(s)split(s,","), ["a";"c,d"], "UniformOutput", false)
ans =
2×1 cell array
{["a" ]}
{2×1 string}