I want to perform certain matrix substraction using vectorization

1 回表示 (過去 30 日間)
MSDataSpl1
MSDataSpl1 2017 年 8 月 2 日
コメント済み: MSDataSpl1 2017 年 8 月 9 日
I have a mtrix say A = [2,5,7]' and another matrix B = [2,7,9]', now i want to subtract B from A in such a way like each element of B will get subtracted from all elements of A, like c = A - B then c should be like (Expected outcome) = [0 3 5, -5 -2 0, -7 -4 -2]
Its like each element of B will get deducted from all elements of A and result will be stored in row wise in new matrix row wise.I dont want to use any loops but only vectorization.
  1 件のコメント
MSDataSpl1
MSDataSpl1 2017 年 8 月 9 日
When i am using this for larger dataset it is causing memory error:
Error using bsxfun Out of memory. Type HELP MEMORY for your options.
Where,
StartTime = currTime(1:LenRxDiv-1);
Data1 = StartTime.';
Data1_s = bsxfun(@minus ,ActTimeStop,Data1);
Value of LenRxDiv is 359574
ActTimeStop is 114020 * 1

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

採用された回答

Jan
Jan 2017 年 8 月 2 日
編集済み: Jan 2017 年 8 月 2 日
A = [2,5,7] % Row vector
B = [2,7,9].' % Column vector
C = A - B % Since R2016b
C = bsxfun(@minus, A, B) % <= 2016a
  1 件のコメント
MSDataSpl1
MSDataSpl1 2017 年 8 月 2 日
Thanks for help Jam Simon, thats working as expected.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by