Distance between all elements of row vector
Show older comments
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.
Accepted Answer
More Answers (1)
madhan ravi
on 18 Feb 2019
Straightforward:
row.'-row
3 Comments
Ana
on 18 Feb 2019
madhan ravi
on 18 Feb 2019
Did you run the code?
per isakson
on 18 Feb 2019
Edited: per isakson
on 18 Feb 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
Categories
Find more on Mathematics in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!