Subtract column vectors from eachother in every possible constelation
5 views (last 30 days)
Show older comments
I have a column matrix "Sample (10,n)" and now I want to subtract the column matrix "Testp (10,n)" from the Sample-matrix. To be more specific, I need to subtract the columns from eachother so that "(Sample(:,1) - TestP(:,1)) + (Sample(:,2) - TestP(:,2)) + ... " will be executed. But it has to be done for every constelation so that for n-th column every entry is taken, than the n-th-1 column switches to the second row-entry and from the n-th vector every value is taken and so on, that in the end I will get a column matrix "gamma (10,don't know".
4 Comments
Guillaume
on 13 Nov 2017
So, does your C also include (b2-y1), (b2-y2), ..., (b3-y1), ... and for the 1st column (a1-x2), ... (a2-x1), ... ?
If so there shouldn't be any I don't know, the number of combinations is size(Sample, 1) ^ (2* size(Sample, 2))
For a 50x10 matrix, that is about 9.7e16 elements something that would require over 710,000 petabytes of memory. I doubt you have anywhere that amount of memory (or the time required to calculate that many elements), so you may want to rethink your problem.
Answers (1)
Jan
on 13 Nov 2017
With some guessing:
n = 7;
Sample = rand(10, n);
Testp = rand(10, n);
gamma = Sample - reshape(Testp, 10, 1, n); % >= R2016b: Auto-Expand
With older Matlab versions:
gamma = bsxfun(@minus, Sample, reshape(Testp, 10, 1, n));
Is this what you want? Perhaps a:
gamma = reshape(gamma, 10, []);
0 Comments
See Also
Categories
Find more on Creating and Concatenating 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!