Distance between all elements of row vector
Afficher commentaires plus anciens
So, I have 1x200 matrix, (row vector). I want to find difference (x(0)-x(1), x(0)-x(2)...) between all elements of an array. How do I do that ?
I should be having 200x200/2 values.
Réponse acceptée
Plus de réponses (1)
madhan ravi
le 18 Fév 2019
Straightforward:
row.'-row
3 commentaires
Ana
le 18 Fév 2019
madhan ravi
le 18 Fév 2019
Did you run the code?
per isakson
le 18 Fév 2019
Modifié(e) : per isakson
le 18 Fév 2019
%%
row = rand(1,6);
c1 = cell2mat( reshape( arrayfun( @(jj) row(jj)-row, (1:6), 'uni', false ), [],1 ) );
%%
c2 = reshape(row,[],1) - row; % The name, reshape, communicates the intent
>> c2-c1
ans =
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
Catégories
En savoir plus sur Numeric Types dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!