random matrix with specific condition in matlab ?
Afficher commentaires plus anciens
how to generate a random matrix except some row or column ? like this
A = [ 1 0 0 0 0 0
1 1 0 1 1 1
0 0 0 0 0 0
1 0 0 0 0 0
1 0 0 0 0 0 ]
I want to generate a random matrix where the first column and second row will be appear in the random matrix like this
A* = [ 1 0 0 1 0 1
1 1 0 1 1 1
0 0 1 1 0 1
1 0 1 0 0 0
1 1 0 1 1 0 ]
Réponses (2)
Azzi Abdelmalek
le 11 Avr 2016
B=randi([0 1],size(A))
B(:,1)=A(:,1)
B(2,:)=A(2,:)
4 commentaires
Firas Al-Kharabsheh
le 11 Avr 2016
Azzi Abdelmalek
le 11 Avr 2016
Not clear
Firas Al-Kharabsheh
le 11 Avr 2016
Modifié(e) : Firas Al-Kharabsheh
le 11 Avr 2016
Azzi Abdelmalek
le 11 Avr 2016
[n,m]=size(A)
B=randi([0 1],n,m)
for k=1:n
if k==2
B(k,:)=A(k,:)
end
end
for k=1:m
if k==1
B(:,k)=A(:,k)
end
end
Image Analyst
le 11 Avr 2016
Try this (I hope it's not homework):
% Make A a random set of zeros and 1s.
A = randi([0, 1], 6, 6);
% Make column 3 all zeros.
A(:, 3) = 0;
% Make row 3 all zeros.
A(3, :) = 0
% Now find the all zero columns.
allZerosColumns = all(A == 0, 1)
% Remove those columns.
A(:, allZerosColumns) = []
% Now find the all zero rows.
allZerosRows = all(A == 0, 2)
% Remove those rows.
A(allZerosRows, :) = []
Catégories
En savoir plus sur Creating and Concatenating Matrices dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!