Obtaning a matrix with the right indexes

4 visualizzazioni (ultimi 30 giorni)
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.
Thank you for your atention.
  2 Commenti
Nuno
Nuno il 17 Apr 2013
Modificato: Walter Roberson il 18 Apr 2013
O.K. I have almost what I want, but now matlab is giving me an error and I can't seem to go around it.
My program:
syms A1 A2 A3 A4;
N=20; %for example
A=sym(zeros(4,N));
B=sym(zeros(4,N));
H=sym(zeros(4,N));
A='A1A2A3A4'
B=1:1:N
C=mat2str(B)
%Concatenation
M=0;
s1=0:N-10
s2=1:N-9
for m=1:N
if m<10
H(1,m)=[A(1:2),C(2*m)];
H(2,m)=[A(3:4),C(2*m)];
H(3,m)=[A(5:6),C(2*m)];
H(4,m)=[A(7:8),C(2*m)];
end
if m>=10
for k=1:N
H(1,m)=[A(1:2),C(2*m+s1(k):2*m+s2(k))];
H(2,m)=[A(3:4),C(2*m+s1(k):2*m+s2(k))];
H(3,m)=[A(5:6),C(2*m+s1(k):2*m+s2(k))];
H(4,m)=[A(7:8),C(2*m+s1(k):2*m+s2(k))];
end
end
end
disp(H)
And the error:
Error using sym>convertExpression (line 2256)
Conversion to 'sym' returned the MuPAD error: Error: Unexpected 'integer'. [line 1, col 4]
Error in sym>convertChar (line 2167)
s = convertExpression(x);
Error in sym>convertCharWithOption (line 2150)
s = convertChar(x);
Error in sym>tomupad (line 1881)
S = convertCharWithOption(x,a);
Error in sym (line 108)
S.s = tomupad(x,'');
Error in sym/subsasgn (line 1614)
if ~isa(B,'sym'), B = sym(B); end
Error in la1 (line 27)
H(1,m)=[A(1:2),C(2*m+s1(k):2*m+s2(k))];
Nuno
Nuno il 17 Apr 2013
Can anyone help me with this?
Thank you.

Accedi per commentare.

Risposta accettata

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

Accedi per commentare.

Più risposte (1)

Ahmed A. Selman
Ahmed A. Selman il 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)
  1 Commento
Nuno
Nuno il 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).

Accedi per commentare.

Community Treasure Hunt

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

Start Hunting!

Translated by