How to store values matrix in cell
이전 댓글 표시
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.
채택된 답변
추가 답변 (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
Tipu Sultan
2019년 5월 13일
KSSV
2019년 5월 13일
It will work...how you have used it? show us the full code.
Tipu Sultan
2019년 5월 13일
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
Tipu Sultan
2019년 5월 13일
카테고리
도움말 센터 및 File Exchange에서 Programming에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!