MATLAB:how can I use fprintf or sprintf to print matrix and vectors with strings togheter? -


i'm @ beginning matlab software ,and have 2 questions:

1) if want print matrix, preceeded string, using fprintf command, how can do? example, print matrix alone, use

fprintf([repmat('%d\t', 1, size(r, 2)) '\n'], r');    

but how can print string followed matrix, togheter in fprintf, without usind disp function ? example, if want print:

>>the matrix inserted [1 3; 4 6] 

2) how can same thing vectors (i know it's particular case of matrix) ? use, example:

>>vectorname=[1 5 2]; >>strtrim(sprintf('%d  ', vectorname)); 

and it's ok numbers of vector, if insert string in spintf result is:

 >>vectorname=[1 5 2];  >>strtrim(sprintf('your vector is:  %d  ', vectorname))   >>your vector 1 vector 5 vector 2 

how can inglobe numbers, 1 ofter other, 1 command (sprintf, fprintf, ecc.)??

thank help!

in both cases can use mat2str.

first case:

input_mat = [1 3; 4 6]; sprintf(['the matrix inserted ' mat2str(input_mat)]) 

ans =  matrix inserted [1 3;4 6] 

second case:

vectorname=[1 5 2]; sprintf(['your vector is: ', mat2str(vectorname)]) 

ans =  vector is: [1 5 2] 

Comments

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -