How to compute calculations on each dimension of the array?

1 view (last 30 days)
Hi, all!
The matrix D is 4096X1610 (spectra X wavenumbers). I want to subtract the average of each spectrum from D and the average of each wavenumber from corresponding wavenumber in D and put the result into a matrix. I have calculated for each dimension but I don't know how to combine results to get 4096X1610 matrix.
mean1 is mean of wavenumbers (1x1610) and mean2 is mean of spectrum (1x4096) from D.
My Code:
D4=D(4096,:)-mean1;
D5=D(:,1610)-mean2';
I want to combine what i have in D4 and D5 such that the dimensions of the output is 4096X1610 for further analysis. Any help is appreciated. Thanks!

Accepted Answer

Matt J
Matt J on 12 Mar 2014
Well, the code you've shown won't work. I think you really mean
D4=bsxfun(@minus,D,mean1);
D5=bsxfun(@minus,D,mean2(:));
Now you say you want to combine D4 and D5 in some way? As in D4+D5 or D4.*D5 ?
As you can see, there are many possibilities. You must define the operation for us.
  3 Comments
Matt J
Matt J on 12 Mar 2014
Edited: Matt J on 12 Mar 2014
So how is that different from computing D4 and D5 as I've showed you? Do you mean this,
D4=bsxfun(@minus,D,mean1);
E=bsxfun(@minus,D4,mean2(:));
Sandeep
Sandeep on 12 Mar 2014
Thank you, Matt! Your code works perfectly. I was trying to do it using for loop which was a bad idea.

Sign in to comment.

More Answers (0)

Categories

Find more on MATLAB 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!