필터 지우기
필터 지우기

change size of matrix without changing number of row and column

조회 수: 1 (최근 30일)
fatema saba
fatema saba 2014년 12월 23일
댓글: fatema saba 2014년 12월 23일
Hi I have 4 matrices (A, B, C and D)like my figure:
The first row and column in matrix B, C and D show number of original row and column.
I want to convert matrix B to matrix B' and matrix C to matrix C' and matrix E to matrix E' like following figure:
is there any clue please?

채택된 답변

Andrei Bobrov
Andrei Bobrov 2014년 12월 23일
B = [0 6 7;6 1 0;7 0 1];
C = [0 1 3 5:7;2 0 0 1 0 0; 3 1 0 0 1 0; 8 0 1 0 0 1; 9 0 0 0 0 1];
E = [0 3:7; 8 0 0 1 0 0;9 1 1 0 1 0; 10 0 1 1 1 0; 11 0 1 1 1 1];
[ib,jb] = find(B(2:end,2:end))
[ic,jc] = find(C(2:end,2:end))
[ie,je] = find(E(2:end,2:end))
s = size(A);
P = [(0:11)',[1:7;zeros(s-1)]];
Bt = P;
Bt(sub2ind(s,B(ib+1,1)+1,B(1,jb+1)'+1)) = 1
Ct = P;
Ct(sub2ind(s,C(ic+1,1)+1,C(1,jc+1)'+1)) = 1
Et = P;
Et(sub2ind(s,E(ie+1,1)+1,E(1,je+1)'+1)) = 1
  댓글 수: 1
fatema saba
fatema saba 2014년 12월 23일
Thank you very much. It was very beautiful. and also complicated for me. It took hours that I understood it.
I had written something like that But I couldent complete it:
i
columnE=[4 5 6 7 8]
rowE=[9 10 11 12]
q=columnE(1,1)
w=zeros(8,12)
[m,n]=size(w)
for i=1:m*n
for j=1:m
if i==q && j==rowE
w(i,[q+j(n)])=[1]
else
w(i)=[0]
end
end
end
[w]

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by