How to store values matrix in cell
조회 수: 1 (최근 30일)
이전 댓글 표시
Hello,
I have an array as follows:
t= [ 1 2 3 ];
A matrix as follows:
M = [t^2 t 1 0 0 0;
0 0 0 t^2 t 1];
Now I want to store the process the M for 3 values of t i.e in this case [1 2 3].How do I do it.
like if t=1
then M=[1^2 1 1 0 0 0;0 0 0 1^2 1 1];
if t=2
then M=[2^2 2 1 0 0 0;0 0 0 2^2 2 1]; and so on.
댓글 수: 0
채택된 답변
Alex Mcaulley
2019년 5월 13일
편집: Alex Mcaulley
2019년 5월 13일
Try this:
t = [1 2 3];
M = arrayfun(@(t) [t^2 t 1 0 0 0; 0 0 0 t^2 t 1],t,'UniformOutput',false);
댓글 수: 3
Alex Mcaulley
2019년 5월 13일
You can use it in your scrip as:
S = [100 0 0 0 0 0;
0 100 0 0 0 0;
0 0 100 0 0 0;
0 0 0 100 0 0;
0 0 0 0 100 0;
0 0 0 0 0 100];
prev_S = S;
Big_lambda = eye(2);
a=0;
b=0;
c=0;
p=0;
q=0;
s=0;
est_vec=[ a ; b; c; p; q; s];
theta = [ 45 46 48] ;
t= [ 1 2 3 ];
r= [200 210 220];
%Wanted = num2cell(M,1)
%[r,b,distance,angle]=deal(Wanted{:})
x = [ r; theta ; t];
%dif_x=zeros(2,3);
M = arrayfun(@(t) [t^2 t 1 0 0 0; 0 0 0 t^2 t 1],t,'UniformOutput',false);
time=4;
for i=1:3
dif_x = [(-cos(theta(i))) (r(i).*sin(theta(i))) (2*a.*t(i)+b);(-sin(theta(i))) (-r(i).*cos(theta(i))) (2*p.*t(i)+q)]
W = dif_x(i)*Big_lambda(i)*dif_x(i)'
pred_x = x+randn(3)
y = M{i} * est_vec + dif_x * (x(:,i)-pred_x(:,i))
K = prev_S*M{i}'/((W + M{i}*prev_S*M{i}'))
%S =prev_S;
est_vec_new = est_vec + K*(y-M{i}*est_vec)
cond = abs(est_vec_new - est_vec)
if cond < 0.003
break
end
est_vec = est_vec_new
a=est_vec(1,1)
b=est_vec(2,1)
c=est_vec(3,1)
p=est_vec(4,1)
q=est_vec(5,1)
s=est_vec(6,1)
S_new = (eye(6) - K*M{i})*S
S = S_new
r_cosTheta = a*time.^2+b*time+c % To calculate x co-ordinate for t>=3
r_sineTheta = p*time.^2+q*time+s % To calculate y co-ordinate for t>=3
%figure,plot(t,meas_equa1)
%new_t=[t,time];
%figure,plot(r_cosTheta,r_sineTheta)
end
%end
추가 답변 (1개)
KSSV
2019년 5월 13일
M = @(t) [t^2 t 1 0 0 0;
0 0 0 t^2 t 1];
t = [1 2 3] ;
iwant = zeros(2,6,length(t)) ;
for i = 1:length(t)
iwant(:,:,i) = M(t(i)) ;
end
댓글 수: 5
KSSV
2019년 5월 13일
clc; clear all ;
S = [100 0 0 0 0 0;
0 100 0 0 0 0;
0 0 100 0 0 0;
0 0 0 100 0 0;
0 0 0 0 100 0;
0 0 0 0 0 100];
prev_S = S;
Big_lambda = eye(2);
a=0;
b=0;
c=0;
p=0;
q=0;
s=0;
est_vec=[ a ; b; c; p; q; s];
theta = [ 45 46 48] ;
t= [ 1 2 3 ];
r= [200 210 220];
%Wanted = num2cell(M,1)
%[r,b,distance,angle]=deal(Wanted{:})
x = [ r; theta ; t];
%dif_x=zeros(2,3);
M = @(t) [t^2 t 1 0 0 0;
0 0 0 t^2 t 1];
t = [1 2 3] ;
iwant = zeros(2,6,length(t)) ;
for i = 1:length(t)
iwant(:,:,i) = M(t(i)) ;
end
time=4;
for i=1:3
M = iwant(:,:,i) ;
dif_x = [(-cos(theta(i))) (r(i).*sin(theta(i))) (2*a.*t(i)+b);(-sin(theta(i))) (-r(i).*cos(theta(i))) (2*p.*t(i)+q)]
W = dif_x(i)*Big_lambda(i)*dif_x(i)'
pred_x = x+randn(3)
y = M * est_vec + dif_x * (x(:,i)-pred_x(:,i))
K = prev_S*M'/((W + M*prev_S*M'))
%S =prev_S;
est_vec_new = est_vec + K*(y-M*est_vec)
cond = abs(est_vec_new - est_vec)
if cond < 0.003
break
end
est_vec = est_vec_new
a=est_vec(1,1)
b=est_vec(2,1)
c=est_vec(3,1)
p=est_vec(4,1)
q=est_vec(5,1)
s=est_vec(6,1)
S_new = (eye(6) - K*M)*S
S = S_new
r_cosTheta = a*time.^2+b*time+c % To calculate x co-ordinate for t>=3
r_sineTheta = p*time.^2+q*time+s % To calculate y co-ordinate for t>=3
%figure,plot(t,meas_equa1)
%new_t=[t,time];
%figure,plot(r_cosTheta,r_sineTheta)
end
%end
참고 항목
카테고리
Help Center 및 File Exchange에서 Smoothing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!