Distance between all elements of row vector
9 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Ana
am 17 Feb. 2019
Bearbeitet: per isakson
am 18 Feb. 2019
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.
0 Kommentare
Akzeptierte Antwort
per isakson
am 17 Feb. 2019
Bearbeitet: per isakson
am 17 Feb. 2019
Hint:
%%
row = rand(1,6);
cell2mat( reshape( arrayfun( @(jj) row(jj)-row, (1:6), 'uni', false ), [],1 ) )
outputs
ans =
0 -0.0790 -0.0644 0.2865 0.0233 0.5075
0.0790 0 0.0146 0.3655 0.1023 0.5866
0.0644 -0.0146 0 0.3509 0.0877 0.5719
-0.2865 -0.3655 -0.3509 0 -0.2633 0.2210
-0.0233 -0.1023 -0.0877 0.2633 0 0.4843
-0.5075 -0.5866 -0.5719 -0.2210 -0.4843 0
4 Kommentare
per isakson
am 18 Feb. 2019
Bearbeitet: per isakson
am 18 Feb. 2019
Yes, arrayfun performs a loop. Roughly
len = 233;
cac = cell( 1, len );
for jj = 1 : len
cac{jj} = center(jj) - center;
end
Weitere Antworten (1)
madhan ravi
am 18 Feb. 2019
Straightforward:
row.'-row
3 Kommentare
per isakson
am 18 Feb. 2019
Bearbeitet: per isakson
am 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
Siehe auch
Kategorien
Mehr zu Logical 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!