필터 지우기
필터 지우기

Computational problem

조회 수: 3 (최근 30일)
Nello Troccia
Nello Troccia 2012년 3월 27일
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!!!

채택된 답변

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

추가 답변 (1개)

Jonathan Sullivan
Jonathan Sullivan 2012년 3월 27일
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

Community Treasure Hunt

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

Start Hunting!

Translated by