Distance between all elements of row vector
Mostrar comentarios más antiguos
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.
Respuesta aceptada
Más respuestas (1)
madhan ravi
el 18 de Feb. de 2019
Straightforward:
row.'-row
3 comentarios
Ana
el 18 de Feb. de 2019
madhan ravi
el 18 de Feb. de 2019
Did you run the code?
per isakson
el 18 de Feb. de 2019
Editada: per isakson
el 18 de Feb. de 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
Categorías
Más información sobre Numeric Types en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!