Quantcast
Channel: MATLAB Central Newsreader Recent Posts
Viewing all articles
Browse latest Browse all 19628

bsxfun do not subtract from same element and 1st column

$
0
0
hi guys,

I have a D excel file (98 rows and 2 columns) and M file(17 rows and 2 col). I need to find difference between 1st row and all rest, 2nd row and all rest ..excluding those rows of which 1st column has same values as in 2nd M file 1st column.
I have this solution:
 [~, idx] = setdiff( D( :, 1 ), M( :, 1 ), 'stable' );
 B = bsxfun( @minus, (permute( D( idx, : ), [1 3 2] )),...
      (permute( D( idx, : ), [3 1 2] )));

The problem is that I need to keep values of the first columns and subtracted values from it. In the example abpve it subtracts 1st columns from files as well and presents them in D(:,:,1) while i need to keep them and in fact i need them to be showed as 10-11,10-12,10-2..etc (i.e. which row was subtracted from which..10 here is the value of the cell in 1st row 1col,11-2nd row 1st col,etc).


..could you give a help on how it would be possible to do that?

Also very important how to avoid bsxfun to subtract from the SAME element(e.g. D(2,2)-D(2,2) ...etc ). I get zeros which I don't need. I tried to change the above code (took me week with no results) but no luck. I'm new in matlab and feeling so stuck. Would be really grateful for any help,

regards,
mira

Viewing all articles
Browse latest Browse all 19628

Trending Articles