Ok this is what I did in Matlab to form the matrix A1 from matrix A
x=1:10;
x=x';
A=toeplitz(x,[x(1);flip(x(2:end))]);
A1=zeros(10,5);
count=0;
for i=1:2:10
count=count+1;
A1(:,count)=A(:,i);
end
The output is as shown
>> A
A =
1 10 9 8 7 6 5 4 3 2
2 1 10 9 8 7 6 5 4 3
3 2 1 10 9 8 7 6 5 4
4 3 2 1 10 9 8 7 6 5
5 4 3 2 1 10 9 8 7 6
6 5 4 3 2 1 10 9 8 7
7 6 5 4 3 2 1 10 9 8
8 7 6 5 4 3 2 1 10 9
9 8 7 6 5 4 3 2 1 10
10 9 8 7 6 5 4 3 2 1
>> A1
A1 =
1 9 7 5 3
2 10 8 6 4
3 1 9 7 5
4 2 10 8 6
5 3 1 9 7
6 4 2 10 8
7 5 3 1 9
8 6 4 2 10
9 7 5 3 1
10 8 6 4 2
The same logic I want in r(i showed only code related to for loop as the rest of the things i.e. initial assignment is the same as Matlab code mention above ), and I tried following in r but it is showing an error. I am a beginner in r programming & need help in the assignment operation of columns of the matrix A to other columns of the matrix A1(empty matrix).
for(i in seq(from=1, to=10, by=2)){
count=count+1
A1[c(1:10),(1:count)]=A[C(1:10),(1:i)]
}
Error in C(1:10): object not interpretable as a factor
In the resultant matrix, I do not want to select particularly odd or even columns of the orignal matrix. but The first column of matrix A1 and matrix A should be the same and the rest of the columns of A1 I can select by changing the step size as shown below in Matlab code
A1 = A(:,1:3:10);
>> A1
A1 =
1 8 5 2
2 9 6 3
3 10 7 4
4 1 8 5
5 2 9 6
6 3 10 7
7 4 1 8
8 5 2 9
9 6 3 10
10 7 4 1
A1 = A(:,1:4:10);
>> A1
A1 =
1 7 3
2 8 4
3 9 5
4 10 6
5 1 7
6 2 8
7 3 9
8 4 10
9 5 1
10 6 2