p_save Change Size on Every Loop Iteration

1 回表示 (過去 30 日間)
Fabio Taccaliti
Fabio Taccaliti 2020 年 5 月 15 日
コメント済み: Fangjun Jiang 2020 年 5 月 15 日
Hello, I wrote this code in Matlab and it sais that p_save change size on every loop iteration (p_save = [p_save p]), so I would like to improve it.
p_save = [];
syms ps
q = linspace(eps,150,60);
for i = 1 : length(q)
A_qs_flut = ps^2*q(i);
DA = det(A_qs_flut);
characteristic_equation = sym2poly(DA);
p = roots(characteristic_equation);
p_save = [p_save p];
end
I know that I can create an array with the right size and then substitute inside the values.
p_save = ones (4, length(q))
My question is: how can I substitute in a smart and fast way the p values inside the p_save array.
Thanks in advance.

回答 (1 件)

Fangjun Jiang
Fangjun Jiang 2020 年 5 月 15 日
p_save(:,i)=p
  2 件のコメント
Fabio Taccaliti
Fabio Taccaliti 2020 年 5 月 15 日
Thanks for the answer, if instead I want to substitute for example p just in the first column and DA in the second and so on for other variables in the other columns what should I write?
p_save(:,1)=p
p_save(:,2)=DA
ecc.. ?
Fangjun Jiang
Fangjun Jiang 2020 年 5 月 15 日
Yes. You would need declare p_save = ones (4, 2*length(q))
p_save(:,2*i-1)=p
p_save(:,2*i)=DA

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

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by