One additionally information. For me it is not important that it is a .csv-file. Any other importable filetype is ok for me as well.
Property value validation with values from file
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Marcel-Dennis Boerzel
am 16 Apr. 2022
Kommentiert: Marcel-Dennis Boerzel
am 24 Apr. 2022
I have a matlab class called Seq with the property seqName. Now I want to verify, if a value assigned to that property is a member of strings which are stored in a .csv file.
I can use mustBeMember
PropName {mustBeMember(seqName,{'movieNameA','movieNameB','movieNameC'})} = 'defaultMovieName'
But how can I replace {'movieNameA','movieNameB','movieNameC'} with an imported .csv file which contains the allowed values?
Thanks in advance
Dennis
1 Kommentar
Akzeptierte Antwort
Steven Lord
am 16 Apr. 2022
The census.mat file contains two variables, cdate and pop.
whos -file census.mat
Let's write a function that will retrieve the data from one of those variables specified by the user.
y = example1698110('cdate')
y = example1698110('pop')
y = example1698110('notInCensus')
function y = example1698110(name)
arguments
% Use a local validator that uses mustBeMember as part of its operation
name string {validateNameInput(name)}
end
y = load('census.mat', name).(name);
end
function validateNameInput(name)
% Use whatever means necessary to assemble the list of acceptable strings
varnames = {whos('-file','census.mat').name};
mustBeMember(name, varnames)
end
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Argument Definitions finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!