Matrix is generating one larger than it should be

3 ビュー (過去 30 日間)
William
William 2025 年 5 月 1 日
コメント済み: William 2025 年 5 月 1 日
Hey there, I'm trying to compare two matrixes, one of which is generated from the other. But the first matrix I make is n by x+1 larger than the second, and I can't seem to figure out what is making it one larger. I've already tried fiddling with when my for loop ends.
function [q]= gen_state(sigx,sigy,Z,T,q0) % sig x and y are noise, like wind, inside system
% Z is number of time points, Y is time between each point, q0 is the
% inital values matrix to put into A
q=zeros(4,Z+1);
x=randn(4,Z+1);
q(:,1)=q0;% SEts first q = to 0
A=[1,T,0,0;0,1,0,0;0,0,1,T;0,0,0,1]; %Creation of A matrix:
B=[0,0,0,0;0,sigx,0,0;0,0,0,0;0,0,0,sigy]; %Creation of B matrix:
for n=1:Z-1
q(:,n+1)=A*q(:,n)+B*x(:,n);
end
  2 件のコメント
Les Beckham
Les Beckham 2025 年 5 月 1 日
Does it help to remove the +1 from this line?
q=zeros(4,Z+1);
William
William 2025 年 5 月 1 日
Yes! That seems to have fixed it!

サインインしてコメントする。

回答 (1 件)

Matt J
Matt J 2025 年 5 月 1 日
編集済み: Matt J 2025 年 5 月 1 日
Does it help to remove the +1 from this line?
Or, perhaps the loop should run from n=1:Z. Otherwise the finalcolumn of q never gets filled.

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

製品


リリース

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by