making the value as 0

8 vues (au cours des 30 derniers jours)
kash
kash le 1 Fév 2012
I have a matrix of 100x100,for ex let us assume 3x3 matrix
A=[2 4 5
6 8 9
1 3 4 ]
now i want to make some matrix as zero,i.e
A1=[2 0 5
0 8 9
1 3 0 ]
A2=[0 0 5
6 8 9]
0 3 4]
please help,like these i need 10 values F A1...A10

Réponse acceptée

Andrei Bobrov
Andrei Bobrov le 1 Fév 2012
A=[2 4 5
6 8 9
1 3 4 ]
n = numel(A);
A1_10 = repmat(A,[1,1,10]);
k = arrayfun(@(j1)randperm(n,3)',(1:10),'un',0);
A1_10(bsxfun(@plus,[k{:}],0:n:n^2))=0
OR
A=[2 4 5
6 8 9
1 3 4 ]
n = numel(A);
A1_10 = repmat(A,[1,1,10]);
k = cell2mat(arrayfun(@(j1)randperm(n)',(1:10),'un',0));
A1_10(bsxfun(@plus,k(1:3,:),0:n:n^2))=0
OR
A=[2 4 5
6 8 9
1 3 4 ]
n = numel(A);
A1_10 = repmat(A,[1,1,10]);
t = ones(size(A));
for j1 = 1:size(A1_10,3)
p = t;
k = randperm(n);
p(k(1:3)) = 0;
A1_10(:,:,j1) = A1_10(:,:,j1).*p;
end
OR
A=[2 4 5
6 8 9
1 3 4 ]
A1_10 = repmat(A,[1,1,10]);
A1_10(rand(size(A1_10))<.3) = 0;
  1 commentaire
kash
kash le 1 Fév 2012
Thanks andrei,can we do the same process using PSO

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Matrices and Arrays dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by