validateattributes() - content of a cell
Ältere Kommentare anzeigen
Dear community,
i am struggling with accessing cells in general and the function validateattributes() in specific.
I want to check the input of my function 'myfun(signals,_otherArguments)'. I expect signals to be of type cell and a row vector. This is easy enough:
validateattributes(signals,{'cell'},{'row'},'','signals',1);
Here are two signals for testing purposes:
badSignal = horzcat({'string1','string2',},cell(1,2), [3,4]);
goodSignal = horzcat({'string1','string2',},cell(1,2), 'string3');
Testing those variables will return nothing since they are both of type cell, just as intended.
But furthermore i would like to ensure, that the content of each cell is of type char while using the error massage handling of validateattributes.
This is where i am stuck.
validateattributes(cellfun(@ischar,signals),{'logical'},'positive'},'','signals',1);
This code is able to check each cells type but the error massage is quite useless to the user. For variable badString is Returns:
Expected input number 1, signals, to be positive.
As you can see the Input number -1- is correct but of course the Information 'expected positive' is not what i intended. Another idea is to loop through signals{:} and check every element with validateattributes() but this will mess up the Input number.
I hope I was able to clearify my Problem.
Any ideas how to check the type of each cell of signals while preserving the error handling of validateattributes?
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Hilfe-Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!