Subtracting one element of an array from all elements of another array
12 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hamid
am 29 Jul. 2022
Kommentiert: Hamid
am 1 Aug. 2022
Dear all,
I have two (40*40) arrays and want to subtract every element of one array from all elements of the other one. Is there any function to avoild using loops? How can I use loops for that? Thank you in advance.
hit1=load ('hit1.mat');
hit2=load ('hit2.mat');
0 Kommentare
Akzeptierte Antwort
Walter Roberson
am 29 Jul. 2022
Bearbeitet: Walter Roberson
am 29 Jul. 2022
result4d = hit1 - permute(hit2, [3 4 1 2]);
This will be 40 x 40 x 40 x 40.
Depending on what you are doing, you might also want to consider something like
result2d = pdist2(hit1(:), hit2(:))
and then reshape() if desired. Note that pdist2 would not be negative.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!