Values of vectors in matrix (changes in time)

조회 수: 2 (최근 30일)
martin martin
martin martin 2019년 3월 11일
댓글: martin martin 2019년 3월 11일
Hello guys, how may I do this..
I have 4 vectors (signals in time)
t =0:pi/20:4*pi;
x1 = cos(t);
x2 = cos(2*t);
x3 = cos(3*t);
x4 = cos(4*t);
And I want to put current value of signal to matrix:
x = [x1 x3]
[x2 x4]
But for t = 0 values of signals in t = 0; for t = t0 + t_step ... etc, Just changes values in matrix in time, I hope you understard :)
Any idea?

채택된 답변

Enthusiastic Student
Enthusiastic Student 2019년 3월 11일
Since all the x variables are functions of the same t variable you should be able to create a matrix by:
for m = 1:length(t)
x(m,:,:) = [x1(m) x2(m);x3(m) x4(m)];
end
This should create a multidimensional array with the first dimension having the same length as t and the two other dimension having a length of 2.
x(10,:,:)
will access the 2x2 matrix for t = t0+9*t_step.
  댓글 수: 1
martin martin
martin martin 2019년 3월 11일
Guys, very thanks for your help. This is it .. ouput matrix x changes values in time
t = 0:1:10;
x1 = t;
x2 = t.^2;
x3 = t.^3;
x4 = t.^4;
for m = 1:length(t)
x = [x1(m) x2(m);x3(m) x4(m)];
end

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

Andrei Bobrov
Andrei Bobrov 2019년 3월 11일
편집: Andrei Bobrov 2019년 3월 11일
t =0:pi/20:4*pi;
x =reshape(cos((1:4)'*t),2,2,[]);

KSSV
KSSV 2019년 3월 11일
t =0:pi/20:4*pi;
x1 = cos(t);
x2 = cos(2*t);
x3 = cos(3*t);
x4 = cos(4*t);
A = zeros(2,2,length(t)) ;
for i = 1:length(t)
A(:,:,i) = [x1(i) x3(i) ; x2(i) x4(i)] ;
end
It can eb achieved without loop also. Read about reshape.

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by