Sum of unequal sized matrices
1 回表示 (過去 30 日間)
古いコメントを表示
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
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
2018 年 8 月 3 日
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 Center および File Exchange で Resizing and Reshaping Matrices についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!