Soustraction between all line of a matrix

2 vues (au cours des 30 derniers jours)
Jonathan Demmer
Jonathan Demmer le 15 Sep 2020
Commenté : Jonathan Demmer le 15 Sep 2020
Hello all,
I have a matrix (6964,1) i would like to do a mathemetical operation between each line of the matrix. i mean line 1 with all the line then line 2 with all the line then line 3 with all the line etc. and I would like that the result return into a new matrix. Can someone help mep lease?

Réponse acceptée

BOB MATHEW SYJI
BOB MATHEW SYJI le 15 Sep 2020
I hope this helps. If not, please rectify. S is your vector. A is a 6964*6964 matrix which returns the difference between other elements of the vector on corresponding columns
A=zeros(length(S));
for i=1:length(S)
for n=(i+1):length(S)
A(n,i)=S(i)-S(n);
end
end
  1 commentaire
Jonathan Demmer
Jonathan Demmer le 15 Sep 2020
Perfect thank you very much!!!!

Connectez-vous pour commenter.

Plus de réponses (1)

madhan ravi
madhan ravi le 15 Sep 2020
bsxfun(@minus, matrix(:), matrix(:).') % for newer versions bsxfun() is not needed

Catégories

En savoir plus sur Matrix Indexing dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by