could anyone help me to solve the issue.

1 view (last 30 days)
I am having two matrices
A =[0.2616 0.2642 0.2658 0.2658 0.2641 0.2606;
0.2131 0.1954 0.1776 0.1596 0.1408 0.1209;
0.1023 0.1066 0.1114 0.1162 0.1202 0.1233;
0.5003 0.4596 0.4150 0.3665 0.3148 0.2612]
B =[ 0 2.2721 2.0537 0 0 1.2945;
2.4707 1.3124 1.3201 0 1.5619 0;
1.2997 0 0 1.8159 1.3116 0;
0 0 0 1.3203 0 1.2975]
I want to get a matrix in such a way that all places of 0 in B should be get filled by the values present in A matrix .
The output of the matrix should be
[0.2616 2.2721 2.0537 0.2658 0.2641 0.2606;
2.4707 1.3124 1.3201 0.1596 1.5619 0.1209;
1.2997 0.1066 0.1114 1.8159 1.3116 0.1233;
0.5003 0.4596 0.4150 1.3203 0.3148 1.2975]
could anyone please help me on this.

Accepted Answer

Torsten
Torsten on 6 Aug 2019
idx = B==0;
B(idx) = A(idx)
  3 Comments
Torsten
Torsten on 6 Aug 2019
A = ...;
w = ...;
w = logical(w);
B = ...;
A(w) = B(w);

Sign in to comment.

More Answers (0)

Categories

Find more on Multidimensional Arrays in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!