필터 지우기
필터 지우기

if i have matrix how to do this operation on it ??

조회 수: 2 (최근 30일)
Firas Al-Kharabsheh
Firas Al-Kharabsheh 2016년 4월 28일
편집: dpb 2016년 4월 29일
and if i have this matrix A , a , b
A = [ 1 3
1 1
2 2
2 0 ]
a = [ 4 which mean how there is one in A
2
4
2 ]
b = [ 2 which mean how there is element in A
2
2
1 ]
after that i want to do this
F = zeros(4,5);
for k=1:n
if m == ( a(k) + ( b(k) - 1 ))
IF the condition is true then goes to the same k row in A and put it in F the ones like that
After apply this loop then in first row and in third row the condition is true
F = [ 1 0 1 1 1
0 0 0 0 0
1 1 0 1 1
0 0 0 0 0 ]
  댓글 수: 3
Firas Al-Kharabsheh
Firas Al-Kharabsheh 2016년 4월 28일
n in number of rows and m is number of columns in F
Firas Al-Kharabsheh
Firas Al-Kharabsheh 2016년 4월 28일
in the loop for example m=5 , first row
if 5 == ( 4 + ( 2-1) ) >>>> true then
look at matrix A in first row {1,3} which mean there is two
group of ones the first group is 1 and the second is three ones and there
is a one zero between the groups this mean is
F(1) = [ 1 0 1 1 1 ]

댓글을 달려면 로그인하십시오.

채택된 답변

dpb
dpb 2016년 4월 29일
편집: dpb 2016년 4월 29일
>> m=5; n=length(A); % define sizes
>> F=zeros(n,m); % preallocate output
>> ix=find(sum(A,2)+sum(A~=0,2)-1==m); % rows contain some ones
>> F(ix,:)=1; % start with all '1'
>> F(sub2ind(size(F),ix,A(ix,1)+1))=0 % zero the locations not '1'
F =
1 0 1 1 1
0 0 0 0 0
1 1 0 1 1
0 0 0 0 0
>>

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by