Hello, I am trying to do the next thing. A matrix A1 with 15 rows and 210 columns of zeros. And I want to complete it with ones in the next form. From point 1 to point 14, all ones. Then a space of 210 zeros, and then again 14 ones. This until the end. I have done the next code, but i obtain this matrix of ones and zeros, but the ones are in columns, instead than in rows.
n=15;
m = n*(n-1);
A1 = zeros(n,m);
for i=1:210:m*n
A1(i:i+13) = ones(1,14);
end
I am looking something like these, but with more ones and zeros:
Thanks for your help.

 채택된 답변

Sean de Wolski
Sean de Wolski 2014년 11월 3일
편집: Sean de Wolski 2014년 11월 3일

0 개 추천

Look at the blkdiag function.
C = repmat({ones(1,4)},1,5)
blkdiag(C{:})
4 and 5 are hardwired to match your above example. Change them to the sizes you need.
doc blkdiag

댓글 수: 3

Carlos
Carlos 2014년 11월 3일
Thanks for the information. i didn't know this comand. But, with the for looo, how would you do that? Because I have other examples that the ones aren't in the diagonal. So I need to use the for loop. Thank you.
Give a small example of starting and ending arrays where the data are off diagonal.
The thing that I don't understand, is why the ones are in the matrix completed in columns. When I put this
A1(i:i+13) = ones(1,14);
They should be in columns, but in the matrix A1 at the end of the loop, they are in rows.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터 및 File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

제품

태그

질문:

2014년 11월 3일

댓글:

2014년 11월 4일

Community Treasure Hunt

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

Start Hunting!

Translated by