필터 지우기
필터 지우기

Sum of unequal sized matrices

조회 수: 1 (최근 30일)
Mukund
Mukund 2018년 2월 3일
댓글: Guillaume 2018년 8월 3일
I have matrix A of fixed size 100x2, and B is a matrix growing in size (row-wise) from 1 to 300 rows. The distance criteria is to be used to find nearest neighbour for every row of A w.r.t. all rows in B. They will be stored as indexes a and b.
The modified A is calculated as A=A+B. Please demonstrate through code, consider A=rand(100,2). B gets formed as max row sum of C=rand(5,2) in every iteration from 1 to 300. I am confused of what to and how to use permute /reshape / repmat
  댓글 수: 2
Image Analyst
Image Analyst 2018년 2월 3일
Please give, for some low iteration, an example of A, B, and C (use small sizes just to demonstrate). I don't even know how many columns B has or what you consider the "distance" to be. And I don't know if you want summing, or vertical concatenation. An example would surely help. Maybe you want pdist2() to compute distances - I don't know, there are still clouds in my crystal ball.
Guillaume
Guillaume 2018년 8월 3일
mukund comment mistakenly posted as an answer moved here:
It is for an idea, may not be accurate. Main iteration
for itr=1:1000 %Main loop
A=rand(100,2) %Fix sized matrix
for i=1:300
C=rand(5,2) %random matrix
[~,cid]=max(sum(C)) %row wise sum
B(i,:)=C(cid,:)
end
for j=1:100
for k=1:size(B,1)
dist(j,k)=sqrt(A(j,:)-B(k,:).^2) % dist of each row in A to each row in B
end
[st,a]=min(dist) %min distance
st(j)=st
b(j)=B(a,:) % index of nearest row in B
end
A=A+B %this step is problematic for me
end
The main aim is to resize B to match A for addition in case its size is less, equal or more.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by