Assert Success in Matlab Without Using Classes

  Kiến thức lập trình

I am writing a validation function in Matlab R2020 to ensure that several arrays meet length requirements before they are processed. The function looks something like

function [arr1, arr2, arr3, arr4] = validate_params_config_format(arr1, arr2, arr3, arr4)
    fprintf("tParameter configuration format is being validated")
    assert(length(arr1)==length(arr2), "tValidation failed: unequal length arr1-arr2")
    assert(length(arr3)==length(arr4), "tValidation failed: unequal length arr3-arr4")
    % other assert statements here
end

If all the assert statements pass, I want to run fprintf("Validation passed").

However, Mathworks documentation only shows how to assertSuccess() for a class, and a Matlab file can only contain one class. I need to have multiple validations for this project, and my colleagues won’t appreciate having multiple files to deal with here.

I am an avid Matlab coder, but new to using assert() statements. How can I detect that all the assert statements in a function returned true, without using classes?

Theme wordpress giá rẻ Theme wordpress giá rẻ Thiết kế website

LEAVE A COMMENT