Posts

How to validate a text in MatLab? - validatestring -- MatLab

 How to validate a text in MatLab? - validatestring -- MatLab How to validate a text in MatLab?  [Ans] validatestring [description] validatestring(s,validateS); It will check validity of s against validateS. validateS is valid when only one of validateS is started with s (the matched string is the only one) , or all of validateS are started with S and any of validateS is the substring of others (the matched string is the shortest length one). When validateS is valid, validatestring function will throw the matched string. Otherwise, it will throw exception. more details on: Check validity of text - MATLAB validatestring (mathworks.com) code clear clc a = findArea( 'Rect' ,10,3, 'cm' ) fprintf( "1\n" ); a = findArea( 'octagon' ,7,13, 'in' ) fprintf( "2\n" ); a = findArea( 'TRI' ,10,3, 'mi' ) fprintf( "3\n" ); function a = findArea(shape,h,w,units) expectedShapes = { 'square' , 'rectangle' , ...

How to format Multiple String with formatted data in MatLab? - compose -- MatLab

 How to format Multiple String with formatted data in MatLab? - compose -- MatLab compose command [Description] It can be used to format the escaped-character ('\') and formatted-character ('%') Its style is very similar to its style of fprintf function. e.g. %compose clear clc TXT = "The quick brown fox jumps" ; TXT = TXT + '\n' + 'over the lazy dog.' ; compose(TXT) %{ "The quick brown fox jumps over the lazy dog." %} fprintf( "1\n" ); F = "pi = %.5f" ; %{ "pi = 3.14159" %} compose(F, pi) fprintf( "2\n" ); F = "pi = %.2f, e = %.5f" ; compose(F, [pi,exp(1)]) %{ "pi = 3.14, e = 2.71828" %} fprintf( "3\n" ); F = "real = %3.2f, imag = %3.2f" ; A = [4+6i;2.3+5.7i;6.1+2i;0.5+7i]; %{ 4×1 string array "real = 4.00, imag = 6.00" "real = 2.30, imag = 5.70" "real = 6.10, imag = 2.00" "real = 0.50, imag =...