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

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -