could anyone help me to get C from A and B

2 visualizzazioni (ultimi 30 giorni)
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 Commenti
Birdman
Birdman il 2 Gen 2018
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 il 2 Gen 2018
Modificato: Guillaume il 2 Gen 2018
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))

Accedi per commentare.

Risposta accettata

Rik
Rik il 2 Gen 2018
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 Commenti
Prabha Kumaresan
Prabha Kumaresan il 3 Gen 2018
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 il 5 Gen 2018
What did you try? You are hopefully aware you can index matrices with a syntax like Y=X([1 3],:);?

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su MATLAB in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by