MATLAB print individual elements of a matrix

  • MATLAB
  • Thread starter gysush
  • Start date
  • #1
gysush
26
0
Consider a matrix A(i,j)

What I want to do example:

A= [1 2 3; 4 5 6; 7 8 9]

I want to to display
1
2
3
4
5
6
7
8
9

I will then save it to a file; I know how to do that. But how do I get matlab to display the individual elements sequentially?

Thank you.

*edit*
Nevermind figured it out...

i.e. A(1,1)=1
 

Answers and Replies

  • #2
mikeph
1,235
18
You can do it a little faster using the reshape command,

Code:
A =

     1     2     3
     4     5     6
     7     8     9

>> reshape(A',9,1)

ans =

     1
     2
     3
     4
     5
     6
     7
     8
     9

This turns the 3x3 matrix into a 9x1 matrix. You need to apply it to A', rather than A, because when Matlab reshapes, it reads down columns first (rather than along rows).

For a general matrix you would use "numel(A)" in place of "9", then you can print huge matrices with one line of code.
 

Suggested for: MATLAB print individual elements of a matrix

Replies
5
Views
662
Replies
1
Views
597
  • Last Post
Replies
2
Views
375
  • Last Post
Replies
2
Views
674
  • Last Post
Replies
1
Views
540
Replies
0
Views
164
Replies
8
Views
711
Replies
0
Views
626
Replies
10
Views
986
  • Last Post
Replies
18
Views
1K
Top