Can a custom argument validation function alter the field names of its input variable?
Show older comments
I'm making a function that takes a scalar or non-scalar struct as one of its inputs, and this struct needs to have 3 fields with specific names: "PD", "RED", and "IR". However, I'm not the only one using this function, and I don't want it to return errors if the user inputs a struct with slightly different field names like "pd" or "Red" or "IR_value".
Usually the input struct itself will be made with a command such as:
inputstruct = struct('PD',{1,2}, 'red',{1,3}, 'ir',{2,4});
In a previous version of this function, I had a nested set of for loops and if statements checking that the input struct's field names at least contain "PD", "RED", or "IR" (ignoring case), and if so, altering the struct fields to exacly match the desired field names if they don't already. There may be other ways of handling this, but so far I've found that altering the field names to match the exact text I want them to be inside the function really helps simplify things when calling values from the input struct later on.
In the current version of my function, I'm trying to add argument validation, and I was wondering if a custom validation function could handle this part of my code.
So my question is: aside from confirming the class and size of my input struct, could I make an argument validation function that "corrects" the struct field names to what they need to be for the rest of the function to work?
So far I can't find a way to make that happen - whenever I step out of the argument validation function, the changes I try to make get undone. I'm not sure if that means I haven't found the right syntax or if argument validation functions simply aren't capable of that sort of thing.
Thanks for the help.
Accepted Answer
More Answers (0)
Categories
Find more on Entering Commands in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!