# Obtaning a matrix with the right indexes

2 views (last 30 days)
Nuno on 15 Apr 2013
My question:
A want to obtain a matrix A(4xN)=[A11 A21 A31 A41; A12 A22 A32 A42; ...; A1N A2N A3N A4N].
So I think that I have to do something like this:
syms A1 A2 A3 A4;
N=10; %for example
A=sym(zeros(4,N));
B=sym(zeros(4,N));
for i=1:N
A(:,i)=[A1; A2; A3; A4]
end
for j=1:N
B(:,j)=[j; j; j; j]
end
C=char(A)
D=char(B)
%And now I have to do a concatenation:
E=strcat([C,D])
%But this won't work of course and I don't know if some part of my program is correct or there is a different approach for this.
##### 2 CommentsShowHide 1 older comment
Nuno on 17 Apr 2013
Can anyone help me with this?
Thank you.

Walter Roberson on 18 Apr 2013
Which MATLAB version are you using? If you are using R2011b or later, try just
A = sym('A', [4 N]);
Nuno on 18 Apr 2013
Thank you Walter Roberson! It makes a lot easier to read the program and it works fine too.

Ahmed A. Selman on 18 Apr 2013
Try this out to see if it solves the issue:
clear
clc
N=20; %for example
H=sym(zeros(N,4));
B=1:N;
%Concatenation
for j=1:4
for m=1:N
H(m,j)=['A',num2str(j),num2str(m)];
end
end
disp(H)
Nuno on 18 Apr 2013
Thank you Ahmed A. Selman! To get what I want I just had to make H(j,m) instead of H(m,j).