フィルターのクリア

Matrix subtraction makes the model too slow

2 ビュー (過去 30 日間)
NN
NN 2021 年 5 月 6 日
コメント済み: Steven Lord 2021 年 5 月 6 日
The below code makes the model too slow:
Data(i,:)=Data1(i,:)-Data2(i,:);
is there any alternative way to solve this ?

回答 (1 件)

Jan
Jan 2021 年 5 月 6 日
No. This is an elementary operation. As long as Data has been pre-allocated properly, this cannot be accelerated or omitted.
If this is really the bottleneck of your code, you cannot change it.
  1 件のコメント
Steven Lord
Steven Lord 2021 年 5 月 6 日
It may be possible to change the code to remove the bottleneck, depending on why it's a bottleneck. If for instance you had a for loop to perform this subtraction on each row in turn and neither Data1 nor Data2 change inside the loops, pulling the subtraction outside the loop and doing the subtraction on the entire Data1 and Data2 arrays may improve the performance especially if the whole arrays are large enough to trigger MATLAB to multithread the subtraction but the individual rows are not large enough.

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

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by