if i have matrix and i want to do this ?
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Firas Al-Kharabsheh
il 3 Mag 2016
Commentato: Firas Al-Kharabsheh
il 3 Mag 2016
if i have this matrix
Matrix_row = [2 4 2 0 0
3 6 0 0 0
4 5 0 0 0
1 2 2 0 0
1 2 1 1 0
1 2 2 0 0
2 3 2 0 0
2 2 2 0 0
1 1 1 4 0
10 0 0 0 0 ]
and i compute this values
a = [ 8
9
9
5
5
5
7
6
7
10 ]
and b = [ 3
2
2
3
4
3
3
3
4
1 ]
i need to chick like this
f = zeros(10,10)
for k=1:10
if a(k) + b(k)-1 == 10 if this condition true then
go bake to Matrix_row(k) and convert this row to be a binary
(the number in Matrix_row shows how many number of ones in this row like
[2 4 2] == [1 1 0 1 1 1 1 0 1 1]
- when the condition is true , the number in Matrix_row in that row must between the group of ones just one zero
the final solution will be
F = [ 1 1 0 1 1 1 1 0 1 1
1 1 1 0 1 1 1 1 1 1
1 1 1 1 0 1 1 1 1 1
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
1 0 1 0 1 0 1 1 1 1
1 1 1 1 1 1 1 1 1 1 ]
2 Commenti
Image Analyst
il 3 Mag 2016
Is this your homework?
The badly-named "a" looks like sum(M, 2). But how did you compute the (also badly-named) "b"?
Risposta accettata
Stalin Samuel
il 3 Mag 2016
clear all
clc
Matrix_row = [2 4 2 0 0
3 6 0 0 0
4 5 0 0 0
1 2 2 0 0
1 2 1 1 0
1 2 2 0 0
2 3 2 0 0
2 2 2 0 0
1 1 1 4 0
10 0 0 0 0 ]
a = [ 8
9
9
5
5
5
7
6
7
10 ]
b = [ 3
2
2
3
4
3
3
3
4
1 ]
f = zeros(10,10)
for k=1:10
tmp = Matrix_row(k,:)
tmp(tmp==0) = [];
if a(k) + b(k)-1 == 10
n1 = 1
for s=1:length(tmp)
f(k,n1:n1+tmp(s))=1;
f(k,n1+tmp(s))=0;
n1 = n1+tmp(s)+1;
end
end
end
f(:,11)=[];
disp(f)
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Numeric Types in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!