How do i save values in a loop to vectors?

How do i save values in a loop to vectors? for my example i want z1 and z2 to becomes vectors of each responding values of Z. Here is my try on writting the code.
-(for n=1:length (Vv)
f=(Vv(n))
A = [Kq+i*(2*pi*f)*Cq-((2*pi*f)^2)*Mq]
G =[0;((kt+i*(2*pi*f)*ct)*Stak)]
Z=A\G;
z1 = Z (1)
z2 = Z (2)
end)

 採用された回答

madhan ravi
madhan ravi 2020 年 12 月 7 日

0 投票

V = cell(2, 1); % an example on how to store
for l = 1 : 2
V{l} = rand(2, 1);
end
celldisp(V)
V{1} = 0.0488 0.2099 V{2} = 0.4665 0.9563

3 件のコメント

martin bjerring
martin bjerring 2020 年 12 月 7 日
thank you for answering, Could you please elaborated on how your values tranlate to my examples? In the example my Z is a column vector with two rows. I want z1 to capture the value of the first row of Z for every n and create a vector of those values. then I want z2 to capture the values of the second row and create a vector of those values.
madhan ravi
madhan ravi 2020 年 12 月 7 日
[z1, z2] = deal( zeros(numel(Vv), 1) );
for n = 1 : numel(Vv)
f = Vv(n);
A = Kq + i * ( 2 * pi * f ) * Cq - ( ( 2 * pi * f ) ^ 2 ) * Mq
G = [0; ( ( kt + i * ( 2 * pi * f ) * ct ) * Stak ) ]
Z = A \ G;
z1(n) = Z(1);
z2(n) = Z(2);
end
martin bjerring
martin bjerring 2020 年 12 月 7 日
Aah I understand now, Thank you!

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeMATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by