Doubt with a for and adding values into a matrix
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Carlos
am 3 Nov. 2014
Kommentiert: Carlos
am 4 Nov. 2014
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.
0 Kommentare
Akzeptierte Antwort
Sean de Wolski
am 3 Nov. 2014
Bearbeitet: Sean de Wolski
am 3 Nov. 2014
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 Kommentare
Image Analyst
am 3 Nov. 2014
Give a small example of starting and ending arrays where the data are off diagonal.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Operating on Diagonal Matrices finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!