input parser on a cell array

11 views (last 30 days)
Paul Mitchell
Paul Mitchell on 27 Feb 2023
Edited: Paul Mitchell on 27 Feb 2023
I have an input cell array example A = {'1234','4567','8901'}
I wish to user the input parser addParameter to check each entry is a string, and also each string is only composed of a set of 4 numbers
is there anyway in which to do this ? I have been searching Help and Answers but cannot find anything
Thank You

Accepted Answer

Rik
Rik on 27 Feb 2023
You can implement a custom validationFcn to check your requirements, as you can read in the documentation.
A = {'1234','4567','8901'};
fcn = @(A) ...
iscellstr(A) && ...
size(vertcat(A{:}),2)==4 && ...
all(isstrprop([A{:}],'digit'));
fcn(A)
ans = logical
1
fcn({'1abc','1234'})
ans = logical
0
  3 Comments
Paul Mitchell
Paul Mitchell on 27 Feb 2023
Edited: Paul Mitchell on 27 Feb 2023
Rik / Stephen - Thank You both very much for taking the time to look at solving my issue. It is much appreciated. Rik your origonal post solved my problem perfectly.

Sign in to comment.

More Answers (0)

Categories

Find more on Argument Definitions in Help Center and File Exchange

Products


Release

R2020a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!