Disp (fprintf ()) prints fprintf and the number of characters. What for?

Coincidentally, I found that it disp(fprintf())prints the string fprintf plus the number of characters it has. I know that disp()is redundant, but just out of sheer curiosity I want to know why it prints the number of characters, as it can be really useful one day. for example

disp(fprintf('Hi %i all of you',2))

leads to

Hello to all of you 15

+4
source share
2 answers

The reason for the specific behavior mentioned in the question is to call FILEprintf fprintfwith a storage variable:

nbytes = fprintf(___) , fprintf , .

, , disp(fprintf(...)) fprintf , disp fprintf, , .

, , STRINGprintf: sprintf:

disp(sprintf('Hi %i all of you',2))
Hi 2 all of you

, , sprintf , , .., fprintf .

str = sprintf(formatSpec,A1,...,An) A1,..., An formatSpec str.

fprintf(fileID,formatSpec,A1,...,An) formatSpec A1,... An . fprintf , fopen.

fprintf(formatSpec,A1,...,An) .

, disp(sprintf()) fprintf , , sprintf, , fprintf.

+11

doc fprintf , fprintf - . , fprintf Hi 2 all of you, disp 15, fprintf.

+6

Source: https://habr.com/ru/post/1614432/


All Articles