MATLAB Answers

How do you align column in a matrix?

4 views (last 30 days)
Mo A
Mo A on 18 Jun 2021
Commented: Mo A on 18 Jun 2021
I'm trying to create this matrix:
However, I'm gettng this:
This is my code:
I'm sure it has something to do with the format operators but I'm not sure what it is.
Thank you for your help in advance
  4 Comments
Mo A
Mo A on 18 Jun 2021
Sorry, here is the code:
Node = [1, 0., 0., 0.;
2,100., 0., 0.;
3,200., 0., 0.;
4,33.3333321,0.,0.;
5,66.6666641, 0., 0.;
6,133.333328,0.,0.;
7,166.666672,0.,0]
fprintf(fid, '%d,%g,%g, %g \n' , Node');

Sign in to comment.

Accepted Answer

Stephen Cobeldick
Stephen Cobeldick on 18 Jun 2021
Node = [1,0,0,0;2,100,0,0;3,200,0,0;4,33.3333321,0,0;5,66.6666641,0,0;6,133.333328,0,0;7,166.666672,0,0]
Node = 7×4
1.0000 0 0 0 2.0000 100.0000 0 0 3.0000 200.0000 0 0 4.0000 33.3333 0 0 5.0000 66.6667 0 0 6.0000 133.3333 0 0 7.0000 166.6667 0 0
fmt = '%3d,%13.9g,%13d,%13d\n';
fprintf(fmt,Node.')
1, 0, 0, 0 2, 100, 0, 0 3, 200, 0, 0 4, 33.3333321, 0, 0 5, 66.6666641, 0, 0 6, 133.333328, 0, 0 7, 166.666672, 0, 0
  1 Comment
Mo A
Mo A on 18 Jun 2021
Thank you Stephen for your help. I'll be sure to include the code as text next time.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!