Why does the following string to number conversion fail in Matlab? -
i'm trying break date , add single number day, month , year
date = input('please enter date (dd/mm/yyyy):','s') tokens = regexp(sprintf(date),'/','split') daymonthyear = str2num(tokens) test = daymonthyear + 1
as error message indicates, str2num
expects strings, not cell array of strings. there 2 ways solve issue. either, can use str2double
, or cellfun
combined str2num
.
solution 1
daymonthyear = str2double(tokens)
solution 2
daymonthyear = cellfun(@str2num,tokens)
Comments
Post a Comment