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)

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by