How to output zeros from a matrix with corresponding matrix of indices for those indeces which are 0 or with negative sign ?
    4 views (last 30 days)
  
       Show older comments
    
Hello
Suppose we have a nonsymetric Toeplitz matrix with zeros or negative numbers. In my case this Toeplitz matrix (might be any size) is a matrix of indicies.
For example:
A = [
0	-1
1	0
2	1
3	2]
Then I have a vector B, which is a signal
If I do 
C=B(A)
I get, the following, which is expected:
Array indices must be positive integers or logical values.
But how to get a Matrix C with the same size as A and set to 0 those elements of C corresponding to zero or negative indeces of A with rest elements corresponding to "normal" indeces?
I tried with logic arrays, set to zero negative elements and find nonzero elements, but since one row can have "normal" indices and zero or negative ones, it did not work for me.
I guess/believe there is short and beautiful solution in Matlab.
Thank you!
0 Comments
Accepted Answer
  Ameer Hamza
      
      
 on 23 Nov 2020
        Something like this will work
A = [
0	-1
1	0
2	1
3	2];
B = [1 5 10];
C = zeros(size(A));
C(A>0) = B(A(A>0))
2 Comments
More Answers (0)
See Also
Categories
				Find more on Resizing and Reshaping Matrices in Help Center and File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
