How can I split comma-separated numbers inside a cell of a cell array?
36 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hi everyone, I have a cell array 200x1 and in each cell I have two or more comma-separated numbers. I would like to create an array in which I have, in each row, one number per cell. For example, if cell {3,1} is 23, 45, 67 I want to create an array in which cell {3,1} contains number 23, cell {3,2} contains number 45 and cell {3,3} contains number 67. Thanks in advance
2 Kommentare
Walter Roberson
am 15 Okt. 2016
Is your input a cell array of strings?
Is your output to be a cell array of split strings, or is your output to be a cell array of numbers of the converted strings?
Antworten (2)
goc3
am 15 Okt. 2016
Let me know if this is what you're looking for:
% define comma-delimited data set
cell_dat = {'13,15,21'; '42,40,47,11,30'; '15,51,23'; '67,76'}
% split comma-delimited sets and convert to number format
cell_dat_split = cellfun(@(x)regexp(x,',','split'),cell_dat,'UniformOutput',0)
2 Kommentare
Walter Roberson
am 16 Okt. 2016
It has to be in a cell because you have a different number entries for each.
Glen's version is splitting the strings but not converting to numeric. My version converts to numeric vectors
Walter Roberson
am 15 Okt. 2016
cell_dat = {'13,15,21'; '42,40,47,11,30'; '15,51,23'; '67,76'};
cell_dat_split = cellfun(@(S) sscanf(S, '%f,').', cell_dat, 'Uniform', 0);
0 Kommentare
Siehe auch
Kategorien
Mehr zu Data Type Conversion finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!