MATLAB Answers

Trying to print a vector.

3 views (last 30 days)
Manuel López
Manuel López on 21 Nov 2020
Commented: Manuel López on 21 Nov 2020
Hi everyone. I'm trying to print a vector as follows:
fprintf(doc,'k0 = [%.3f %.3f %.3f %.3f].',k0);
where k0 is a 4-dimensional vector with numerical components and doc is a .txt document. Nonetheless, I would want to print any other vector k0 without making explicit reference to its dimension. I mean, I would like to change de dimension of k0 and not changing the code. Can someone help me?
Thanks!

  0 Comments

Sign in to comment.

Accepted Answer

dpb
dpb on 21 Nov 2020
fprintf(doc,['k0 = ' repmat('%.3f ',1,numel(k0)) '.'],k0);

  1 Comment

Manuel López
Manuel López on 21 Nov 2020
Thank you :)

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!