MATLAB: How to print a ‘%’ character using SPRINTF in MATLAB 7.7 (R2008b) MATLAB I would like to print a string containing the '%' character. However, when I attempt the following: sprintf('100%') The output reads: 100 Best Answer To escape the percent symbol, use two percent signs. For example:sprintf('100%%')Yields the output: 100% Related SolutionsMATLAB: Simple way to wrap quotes around input One way:str = sprintf('''%s''', usersString) MATLAB: How to initialize a variable to zero in userdefined matlab function, which should be executed only once then the values should change dynamically Such cases are handled using persistent variables.function [ia_avr] = fcn(ia) persistent iasum ia_num ia_avr_old if isempty(iasum) % only runs once iasum = 0; ia_num = 0; ia_avr_old = 0; end iasum = iasum+Ia; if xxxx ia_num=ia_num+1; ia_avr=ia_avr_old; elseif xxxx ia_num=ia_num+1; ia_avr=iasum/ia_num; ia_avr_old=ia_avr; else ia_avr=ia_avr_old; iasum=0; ia_num=0; endend Related QuestionHow to replace double quotes with two single quotes in string in MATLAB (R2013a)Finding occurences of a string in a text string and storing locations of the occurencesSprintf format specifiers won’t print newline
Best Answer