Subtract column vectors from eachother in every possible constelation

5 ビュー (過去 30 日間)
Kuba
Kuba 2017 年 11 月 13 日
コメント済み: Kuba 2017 年 11 月 13 日
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 件のコメント
Guillaume
Guillaume 2017 年 11 月 13 日
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.
Kuba
Kuba 2017 年 11 月 13 日
I assumed it would be a large number of combinations, but wow 9.7e16 elements?! I clearly have to rethink this :P
But thank you for your quick help!

サインインしてコメントする。

回答 (1 件)

Jan
Jan 2017 年 11 月 13 日
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, []);

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by