So I've using App Designer to import a file. I'm giving the user an option to pick Beginning and Endings dates for the file that they are importing. Here is some of my code that I've used in the past (as a function) to check to see if the user put anything for the Beginning dates and if they did, it uses 'datetime' and 'timerange' to and the dates to the readtable function.
if ~isempty(app.BeginningEditField.Value)
app.BeginningEditField.Value = datetime(app.BeginningEditField.Value,'InputFormat',app.OutputDateTimeStringFormat);
app.EndingEditField.Value = datetime(app.EndingEditField.Value,'InputFormat',app.OutputDateTimeStringFormat);
TR = timerange(app.BeginningEditField.Value, app.EndingEditField.Value, 'closed');
InTable = InTable(TR,:);
end
The variable app.OutputDateTimeStringFormat is set to 'yyyy/MM/dd HH:mm:ss'
Whever I type in a date in the Beginning and Ending Edit Field (with the same format as the app.OutputDateTimeStringFormat) I get this error.
Error using matlab.ui.control.EditField/set.Value (line 98)
'Value' must be a character vector or a string scalar.
I've tried using 'num2str(app.BeginningEditField.Value)' to possible change that into a string which could be used with this function but that does not work.
P.S. this error occurs on the 2nd and 3rd line. (where it uses 'datetime' function)
2 Comments
Direct link to this comment
https://au.mathworks.com/matlabcentral/answers/540704-error-using-matlab-ui-control-editfield-set-value-value-must-be-a-character-vector-or-a-string-s#comment_880829
Direct link to this comment
https://au.mathworks.com/matlabcentral/answers/540704-error-using-matlab-ui-control-editfield-set-value-value-must-be-a-character-vector-or-a-string-s#comment_880829
Direct link to this comment
https://au.mathworks.com/matlabcentral/answers/540704-error-using-matlab-ui-control-editfield-set-value-value-must-be-a-character-vector-or-a-string-s#comment_880853
Direct link to this comment
https://au.mathworks.com/matlabcentral/answers/540704-error-using-matlab-ui-control-editfield-set-value-value-must-be-a-character-vector-or-a-string-s#comment_880853
Sign in to comment.