Asked by Krishna Prasad Rao
on 31 Jan 2013

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

*No products are associated with this question.*

Answer by Thorsten
on 1 Feb 2013

Accepted answer

It's easy as

disp(H_Mat)

Krishna Prasad Rao
on 1 Feb 2013

It Works thanks!

Answer by Shashank Prasanna
on 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',' ')

Krishna Prasad Rao
on 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

Answer by Image Analyst
on 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,

Show 4 older comments

Krishna Prasad Rao
on 1 Feb 2013

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

Image Analyst
on 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.

Krishna Prasad Rao
on 5 Feb 2013

Thank you! Now i understand it!

Related Content

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn moreOpportunities for recent engineering grads.

Apply Today
## 0 Comments