フィルターのクリア

How to store Values in a Loop?

1 回表示 (過去 30 日間)
naresh bhimchand
naresh bhimchand 2019 年 11 月 11 日
コメント済み: naresh bhimchand 2019 年 11 月 12 日
for t=0:1:10
L(t) = 3*cos(t);
M(t) = diag([L 5*cos(t) 7*cos(t)]);
K(t) = [12e5*cos(t) 18e5*cos(t) 34e5*cos(t);18e5*cos(t) 15e5*cos(t) 12e5*cos(t);13e5*cos(t) 12e5*cos(t) 22e5*cos(t)];
[X,e] = polyeig(K, M)
o = sqrt(e);
fprintf('the freqeuncy is"%d" \n',o)
writematrix(o,'hello/tt.xlsx','sheet',1,'range','A1:A30');
end
Hi, From the above code I am trying to store 10 time series in a single excel file but I can't able to do it and getting a error like "Array indices must be positive integers or logical values". Can anyone please help me in this.
Thank you in Advance.
  4 件のコメント
Walter Roberson
Walter Roberson 2019 年 11 月 12 日
編集済み: Walter Roberson 2019 年 11 月 12 日
Your L is increasing in length each iteration For each length of L, you diag() including all of L, so your M diagonal matrices are increasing in size each iteration. Your K matrix is not increasing in size each step. You ask to polyeig all of the K matrices and M matrices together. There are ways that all of the K and M matrices can be dropped into a single call, like polyeig(first_k, second_k, third_k, ..., first_m, second_m, third_m, ...) and your K matrices are all the same size, and your first M matrix is the same size as your K matrices, but your second M matrix is larger than the K matrices and the first M matrix, so by the second iteration you would be trying to polyeig() a series of matrices that included at least two different sizes, which is not permitted for polyeig.
Remember, if you expect M(t) to represent an entire matrix, then M without a subscript has to refer to all of the M matrices together, some-how.
naresh bhimchand
naresh bhimchand 2019 年 11 月 12 日
ok bro thank you very much

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

採用された回答

David Hill
David Hill 2019 年 11 月 12 日
for t=0:10
L = 3*cos(t);
M = diag([L 5*cos(t) 7*cos(t)]);
K = [12e5*cos(t) 18e5*cos(t) 34e5*cos(t);18e5*cos(t) 15e5*cos(t) 12e5*cos(t);13e5*cos(t) 12e5*cos(t) 22e5*cos(t)];
[X,e] = polyeig(K, M)%X is a 3x3 matrix, e is 3x1 vector
o(:,t+1) = sqrt(e);%o is a 3x11 matrix when the loop finishes
end
writematrix(o,'hello/tt.xlsx','sheet',1,'range','A1:A30');
The only thing you are writing to file is the variable o; therefore it is the only thing needing to be in an array.
  3 件のコメント
Walter Roberson
Walter Roberson 2019 年 11 月 12 日
If your o is ending up as 3x11 then it has all of the iterations in it.
Note that you are calculating 33 values not 30, because 0:10 is 11 iterations not 10; and that you are asking to write the 3x11 martrix into a 30x1 array. Perhaps you should change the 0:10 to 0:9 and perhaps you should writematrix o(:) instead of o
naresh bhimchand
naresh bhimchand 2019 年 11 月 12 日
I got it, bro.Thanks :)

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeVariables についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by