getting error when using diag command
3 次查看(过去 30 天)
显示 更早的评论
hello i am doing simulation related to duct to control noise and i have structure of matrices, for example i am creating Anr matrices the An and then i want to create Atilta which contains all these matrices according formulas but when i am using diag it gaves me error related to scalar what should i do ?
the formulas are following
*********************
Nmod = 5; % modes in duct 1 to 5
L = 1.2; % length of duct
K = 0.051; % impedance at one end
zi = 0.315;
zm = 0.775;
c = 340 ;
roh = 1.225;
S = 1;
eta =1 ;
betan = -(1:Nmod)*pi/L;
alfa = 1/(2*L)*log((1-K)/(1+K));
Atilta = []; % final matrices
for i = 1:Nmod
%
Anr = c * [alfa betan; -betan alfa]; % formula for Anr matrices
%
Ani = c*eta*[1 0;0 1];
%
An = [Anr -Ani ; Ani Anr]; % Anr and Ani matrices pack in An
Atilta = diag(Atilta,An);
end
***************
from this i want to create state space matrices
and my Atilta matrix will be like this
but when i am using diag command it will give me error as following
Error using diag
K-th diagonal input must be an integer scalar.
Error in modeNmatrices (line 41)
Atilta = diag(Atilta,An);
回答(1 个)
Walter Roberson
2013-5-5
When you use the two-argument form of diag(), the second argument needs to be the number of the diagonal. You cannot use diag() to directly modify an existing array.
I am confused: your error message uses diag() but your code uses blkdiag() which can take an array as its second argument.
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!