could anyone help me to get C from A and B

2 次查看(过去 30 天)
If A =
1 2 3 4 5
11 12 13 14 15
6 7 8 9 10
21 22 23 24 25
26 27 28 29 30
B =
0 0 41 0 0
45 0 0 0 0
0 43 0 0 0
0 0 0 42 0
0 0 0 0 44
and
C =
0 0 41 4 0
45 12 0 0 15
6 43 0 0 10
0 0 23 42 0
26 27 0 0 44
How to obtain C from A and B. the example mentioned here is for (5,5) if it is for (50,100) how it can be done?
  2 个评论
Birdman
Birdman 2018-1-2
What is your condition for obtaining? There is not a certain pattern or something else for achieving C from A and B.
Prabha Kumaresan
Prabha Kumaresan 2018-1-2
编辑:Guillaume 2018-1-2
In the example mentioned i am clustering (row 1, row 4) and (row2,row3,row5) from B . As a result of clustering (row1,row4) from B, which has values of(41 in(1,3),42 in(4,4)) gets modified into (41 in (1,3) and 4(from A) in (1,4),23(from A) in (4,3) and 42 in (4,4)).the same condition applies to clustering of ((row2,row3,row5))

请先登录,再进行评论。

采纳的回答

Rik
Rik 2018-1-2
Let me start off by saying you described it very poorly (and formatting your comment as code doesn't help).
What seems to be the goal is adding values to B. The rule for this is that in groups of rows, the entire column must be either 0 or contain a value. If B on that position is equal to 0, the value is taken from A.
For rows 1 and 4:
cluster=[0 0 41 0 0;
0 0 0 42 0];
non_0= sum(cluster);
non_0=repmat(non_0,2,1);
A_part=[1 2 3 4 5;
21 22 23 24 25];
new_cluster=cluster;
new_cluster(non_0 & cluster==0)=A_part(non_0 & cluster==0);
So now the question is how to generalize this to inputs of rows. Personally, I think you should be able to use this code a basis to write your own code for arbitrary row groups. The only thing you need to write is how to extract the clusters and put them back.
  3 个评论
Prabha Kumaresan
Prabha Kumaresan 2018-1-3
Could you please help me to have an arbitrary row groups by extracting the clusters and putting them back as i was struggling from morning.
Rik
Rik 2018-1-5
What did you try? You are hopefully aware you can index matrices with a syntax like Y=X([1 3],:);?

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 MATLAB 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by