I want print the matrix, in orginal matrix from but it displays it as a series of coloumns.

1 Ansicht (letzte 30 Tage)
H_Mat=[1, 0, 1, 0, 1, 0, 1, 0;
1, 0, 0, 1, 0, 1, 0, 1;
0, 1, 1, 0, 0, 1, 1, 0;
0, 1, 0, 1, 1, 0, 0, 1];
[row,coloumn]=size(H_Mat);
for i = 1:row
for j = 1:coloumn
fprintf (' %d,', H_Mat (i,j));

Akzeptierte Antwort

Thorsten
Thorsten am 1 Feb. 2013
It's easy as
disp(H_Mat)

Weitere Antworten (2)

Shashank Prasanna
Shashank Prasanna am 31 Jan. 2013
Try:
H_Mat=[1, 0, 1, 0, 1, 0, 1, 0; 1, 0, 0, 1, 0, 1, 0, 1; 0, 1, 1, 0, 0, 1, 1, 0; 0, 1, 0, 1, 1, 0, 0, 1];
dlmwrite('test1.txt', H_Mat,'delimiter',' ')
  1 Kommentar
Krishna Prasad Rao
Krishna Prasad Rao am 31 Jan. 2013
Bearbeitet: Krishna Prasad Rao am 31 Jan. 2013
Actually i miss spelled the question, it gives series of rows as i see, but i want it to print so it looks like a Matrix. Thanks

Melden Sie sich an, um zu kommentieren.


Image Analyst
Image Analyst am 31 Jan. 2013
Perhaps you just need to swap the order of rows and columns in the for loops, and add a new line:
for j = 1:row
for i = 1:coloumn
fprintf (' %d,', H_Mat (j,i));
end
fprintf ('\n');
end
In the command window:
1, 0, 1, 0, 1, 0, 1, 0,
1, 0, 0, 1, 0, 1, 0, 1,
0, 1, 1, 0, 0, 1, 1, 0,
0, 1, 0, 1, 1, 0, 0, 1,
  7 Kommentare
Image Analyst
Image Analyst am 1 Feb. 2013
Bearbeitet: Image Analyst am 1 Feb. 2013
The colon, when used where you'd normally use an index, means "all". So in your case, where the colon is in the first index, which corresponds to the "rows" index, the colon mean "all rows". So X(:,p) means "all rows in column #p." Basically it extracts out the pth column from the matrix into a vertical column vector.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by