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

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));

Más respuestas (2)

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 comentario

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

Iniciar sesión para comentar.

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 comentarios

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
I don't know how you can do that. I mean, like putting the gigantic brackets going up and down the entire left and right side. Perhaps with Latex or something, but I don't know. Maybe you can use ActiveX to create something like that in Microsoft Word's equation editor. Where do you need this pretty-looking depiction of the matrix? Is it OK to be in a Word document? Because I'm not sure you can have that in the command window, where I've seen only normal ASCII text.
ok, I dont know how to do that. Actually i was using the c++ for printing the matrix and it printed like as i expected but not in Matlab, so i tried to know if there is any way to display it in the command window by using Matlab. Thanks
Krishna, MATLAB command like is not exactly for pretty printing, atleast not at this moment. You can try mupad if you have the symbolic toolbox which does do better. Other than that you are out of luck in the MATLAB environment.
I got it now, thanks :)
hey can you please explain me what does this expression mean? W = X(:,p);
the original situation where i use this one is
function Y = SecondStage(H_Mat,V,X,Z)
Y = zeros(size(H_Mat));
for q = 1:4
for p = 1:8
W = X(:,p);
W(q)=[];
W = sum(W);
%update every node through variables.
Y(q,p)=H_Mat(q,p)*(V(p)+W);
end
end
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.
Thank you! Now i understand it!

Iniciar sesión para comentar.

Categorías

Más información sobre Operators and Elementary Operations en Centro de ayuda y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by