Finding and Storing element row-wise when the matrix has SYM.

조회 수: 2 (최근 30일)
P K
P K 2018년 12월 25일
편집: madhan ravi 2018년 12월 25일
Hello everyone, I have a doubt. Suppose i have a matrix whose size is N X M. Lets consider a 6X3 matrix.
A=[1 0 0; 7 0 0;4 5 0;3 5 0;1 4 7; 8 2 1];
What i want to perform is to obtain a new ROW-MATRIX which contain only non-zero element.So the answer would be
1
7
4
5
3
5
1
4
7
8
2
1
Can someone help be with this. My matrix is very large and it containg syms instead of numbers,

채택된 답변

madhan ravi
madhan ravi 2018년 12월 25일
편집: madhan ravi 2018년 12월 25일
A=[1 0 0; 7 0 0;4 5 0;3 5 0;1 4 7; 8 2 1];
nonzeros(double(reshape(A',[],1)))
^^^^^^----converts to a double from sym or just use vpa (does the same work as double)
Gives:
ans =
1
7
4
5
3
5
1
4
7
8
2
1
  댓글 수: 2
P K
P K 2018년 12월 25일
Thanks @madhan.
I had to just do this.TRANSPOSE
ans=nonzeros(A')
But, i was getting error with your code when i used it in my case.
Error using symengine
Unable to convert expression into double array.
Anyway thanks.
madhan ravi
madhan ravi 2018년 12월 25일
편집: madhan ravi 2018년 12월 25일
Anytime :) , glad you worked it out
Note: Don't name a variable ans (use some other names instead).

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by