Create an array that has ones
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Sean Raffetto
le 14 Juil 2016
Modifié(e) : Andrei Bobrov
le 14 Juil 2016
Hello,
I am trying to create a 1x256 cell array where each matrix inside is 256x41. I want each matrix to have a row of ones and the rest zeroes. For example, the first matrix will have the first row be ones and the rest zeroes. The second matrix will have the second row be all ones with the first row and all the rows after the second row be zeroes. Help? I'd like to loop this.
Thanks
0 commentaires
Réponse acceptée
Azzi Abdelmalek
le 14 Juil 2016
A=arrayfun(@(x) circshift([zeros(1,41);ones(255,41)],[x 1]),1:255,'un',0)
Plus de réponses (1)
Andrei Bobrov
le 14 Juil 2016
Modifié(e) : Andrei Bobrov
le 14 Juil 2016
num2cell(permute(repmat(eye(256),1,1,41),[1,3,2]),[1,2])
or
num2cell(bsxfun(@eq,(1:256)'*ones(1,41),reshape(1:256,1,1,[])),[1,2])
or
m = 256;
n = 41;
a = [ones(1,n);zeros(m,n)];
C = cell(m,1);
for jj = 1:m
ii = jj + 1;
a([jj,ii]) = a([ii,jj]);
C{jj} = a(2:end,:);
end
0 commentaires
Voir également
Catégories
En savoir plus sur Matrices and Arrays dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!