How can I built a new matrix in a new method?

조회 수: 6 (최근 30일)
Ayob
Ayob 2014년 1월 18일
댓글: Paul 2014년 1월 18일
I have a matrix like Assem{1} which is equal to:
Assem{1}=[0 6 2 0 0 7 0 0 0 12 3 0 1]
My another matrix is:
C=[W1 W2 W3 W4 W5 W6 W7 W8 W9 W10 W11 W12 W13], (W1 to W13 are defined values)
I want to use " D(Assem{i})=C " to define a new matrix D which is assembeled by members of matrix C with the help of matrix Assem{1}.
But, As you see some members of Assem{1} have zero values and doesn't lead to any position in D. So, I want to clear members with zero values of matrix Assem{1} and it's equivalent members in matrix C in order to be able built my matrix with the method of " D(Assem{i})=C ".
So
Assem{1} shold change to Assem{1}=[6 2 7 12 3 1]
C should change to C=[W2 W3 W6 W10 W11 W13]
How can I do these two steps with Matlab matrix methods.
[Note: Assem{i} has different values, I mentioned Assem{1} for i=1 as an example]

채택된 답변

Paul
Paul 2014년 1월 18일
ind = find(Assem{1}==0);
Assem{1}(ind)=[];
C(ind)=[];
  댓글 수: 2
Ayob
Ayob 2014년 1월 18일
This is not right . My program should find zero members in Assem{1} and then clear for example second member and fourth member in Assem{1} which are zero and then clear second and fourth members in matrix C whether they are zero or not.
Paul
Paul 2014년 1월 18일
That code does exactly what you describe. If not, tell me why it's wrong according to you.

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

추가 답변 (0개)

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by