Hi, I have two arrays A and B as below
A=load('A.txt');B=load('B.txt');
where
A=12345678910
and
B=1 43 106 158 179 59
Goal: I want to construct an array C with the same length as A. The elements of C equals the elements of the second column of B if the elements of the first column of A and the elements of the first column of B are equal. Otherwise, the elements of C is not available (NaN)
Thus, C should look like below:
C=1 42 NaN3 104 NaN5 NaN6 157 NaN8 179 5910 NaN
I tried the following command lines:
C=zeros(size(A));for i=1:numel(A); for j=1:numel(B);if A(i)=B(j); C(i)=B(j,2); else C(i) = NaN;end;end;
but had no success yet. I wonder if someone could help me to correct the mistakes I have done or suggest something else that works.
I thank you in advance for you help
Emerson
Best Answer