MATLAB: Changing the cell values into normal columns

changeing the cell values into normal columns

hello all, i have string data which contains 3groups in one cell how i can change into normal array i mean each character with one column. for instance
Data={'020';'1014';,000'};
how i can change those into each value in one column except 1014 which i want to store as 1 for one column and 0 for one column but 14 in one column as pair.
help me for solving this problem.

Best Answer

  • A simple one-line solution using sscanf inside of cellfun and cell2mat:
    >> Data={'020';'1014';'000'};
    >> cell2mat(cellfun(@(s)sscanf(s,'%1f%1f%f'),Data, 'UniformOutput',false))
    ans =
    0
    2
    0
    1
    0
    14
    0
    0
    0
    Note the format string used in sscanf: the %1f token parses just one character, thus allowing the automatic parsing of the first two characters individually.