Computational problem

2 vues (au cours des 30 derniers jours)
Nello Troccia
Nello Troccia le 27 Mar 2012
Hi
this is a semplification of my problem. I have 2 matrix
A=(1:1:4)';
B=(10:10:120)';
and I need to define a new matrix (column vector) C that is composed by 12 elements. The first 3 elements are the first term of A, the seconds 3 elements are the second term of A, and so on. In this case C=[1 1 1 2 2 2 3 3 3 4 4 4]' How could I do? take in consideration that in reality I cant define a new matrix. The real problem is:
T=1200;
n=6
m=5
g=m*n
p = 2:(n-1);
for j1 = numel(p):-1:1
cc(:,j1) = (2+(m*(p(j1)-1))):1:(m*p(j1)-1);
end
cc = cc(:).';
((2.718.^(-(m-rem(cc,m)-1)))') .* (T^4-(x(p*m+g).^4))';
i.e. B i.e. A
the first part is a column vector of 12 elements and the second part is a column vector of 4 elements. (the term (x(p*m+g) is part of a column vector and is composed of 4 elements). So I need to get a column vector of 12 elemets from the second part of the code without define a new matrix and it must be define as C. Help me!!!

Réponse acceptée

Walter Roberson
Walter Roberson le 27 Mar 2012
For the first part of the question, the solution is
C = kron(A, ones(3,1));

Plus de réponses (1)

Jonathan Sullivan
Jonathan Sullivan le 27 Mar 2012
You might not need to. It sounds like bsxfun would help you out. You essencially want to multiply every element of vector A with every element of vector B.
Check this out.
A=(1:1:4); % row vector
B=(10:10:120)'; % column vector
C = bsxfun(@times,A,B) % matrix

Catégories

En savoir plus sur Mathematics dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by