random matrix with specific condition in matlab ?
Ältere Kommentare anzeigen
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 ]
Antworten (2)
Azzi Abdelmalek
am 11 Apr. 2016
B=randi([0 1],size(A))
B(:,1)=A(:,1)
B(2,:)=A(2,:)
4 Kommentare
Firas Al-Kharabsheh
am 11 Apr. 2016
Azzi Abdelmalek
am 11 Apr. 2016
Not clear
Firas Al-Kharabsheh
am 11 Apr. 2016
Bearbeitet: Firas Al-Kharabsheh
am 11 Apr. 2016
Azzi Abdelmalek
am 11 Apr. 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
am 11 Apr. 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, :) = []
Kategorien
Mehr zu Creating and Concatenating Matrices finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!