MATLAB: Split information from the same cell into diferent cells

delimiterMATLABxlsreadxlsx

Hello, I have an excel file and it has 2 columns and a lot of lines. The first column has numbers and the second column has words like this "House_red". I used this to extract the second column
[~,houses] = xlsread('houses.xlsx', 'B:B');
And right now I have all my information separated numbers from strings, but in the strings I wanted to split house from red where house will be in the first column and red in the second column. Is there a way to do split strings from the same line into different lines/columns?

Best Answer

Try this:
houses = {'House_red'; 'House_blue'; 'House_green'};
s = regexp(houses, '_', 'split');
H = cellfun(@(x)x(:,1), s);
C = cellfun(@(x)x(:,2), s);
HC = [H, C]
HC =
3×2 cell array
{'House'} {'red' }
{'House'} {'blue' }
{'House'} {'green'}