Finding and Storing element row-wise when the matrix has SYM.
1 view (last 30 days)
Show older comments
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,
0 Comments
Accepted Answer
madhan ravi
on 25 Dec 2018
Edited: madhan ravi
on 25 Dec 2018
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 Comments
madhan ravi
on 25 Dec 2018
Edited: madhan ravi
on 25 Dec 2018
Anytime :) , glad you worked it out
Note: Don't name a variable ans (use some other names instead).
More Answers (0)
See Also
Categories
Find more on Number Theory in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!