Column 1 of array A contains the index number of the samples; other columns of matrix A contain other attributes of each sample, (in array B, the first two cell along each row contain an attribute and the index number of a sample). when I have one thousand rows, it becomes inefficient to use the code below. Please is there a more efficient way to write the code such that one does not have to input the thousands of numbers in the code.
Columns 2, 4 and 6 of array B contain the index number of samples contained in matrix A. I am trying to insert corresponding sample attribute in column 4 of array A (based on corresponding index number in array A and B) into new 3rd, 6th and 9th column of matrix B; to have matrix C as shown below:
A = [1,3.43,2.34,5.43,3.22;
B = [0.12,2,0.15,1,0.65,3;
The code below works but with over a thousand column, it becomes inefficient to write all the numbers in line 2 of the code below:
I am trying to write a code that does not require one to write all the numbers of the columns as in line 2 of the code below.
I get reasonable result with this code but having to type millions of numbers for every run makes it inefficient.
Z = [0;0;0];
C = [[B(:,1:2) Z B(:,3:4) Z B(:,5:6)]];
for j = 1:3
for i = 1:3
n = A(find(ismember(A(:,(1)), B(i,j*2), 'rows')),4);
C(i,j*3) = n;