Subtracting values in an array between all the elements one by one

1 回表示 (過去 30 日間)
MichaelO
MichaelO 2020 年 6 月 30 日
コメント済み: MichaelO 2020 年 7 月 7 日
Hi y'all!
I have to substract values from an array of 2192 days (lines) and 1000 values (columns) one by one. size(Qref) = 2192 x 1000. For example. Qref(x1,y1) - Qref(x1,y2); Qref(x1,y1) - Qref(x1,y3); Qref(x1,y1) - Qref(x1,y4)...... then, Qref(x1,y2) - Qref(x1,y3), Qref(x1,y2) - (x1,y4), (x1,y2) - (x1,y5), ....and so on until Qref(x2192,y999) - Qref(x2192,y1000). I have to run that 14th times by 5 cuz it is for a 14th days lead time and 5 bassins. I wrote the following code but takes so much time (almost 6 days) so; if someone can help me to make a simpler code I will really appreciate it.
% Qref is generated 14 times for 5. So, once this loop is finished it is going to be repeated 13 times more, then 5 times
Qref = rand(2192,1000)
for idays = 1:2192
for ii = 1:1000-1
for ik = ii+1:1000
D0(idays,ik,ii) = abs(Qref(idays,ii)-Qref(idays,ik));
end
end
end
Thanks in advance!

採用された回答

madhan ravi
madhan ravi 2020 年 6 月 30 日
[X, Y] = meshgrid(x,y);
XY = [X(:), Y(:)];
Wanted = -diff(XY)
  1 件のコメント
MichaelO
MichaelO 2020 年 7 月 7 日
Thank you so much, that helps me alot!

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

その他の回答 (0 件)

カテゴリ

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