How can I perform an operation on each element of a vector individually using a for loop?

7 ビュー (過去 30 日間)
I have impedance values from a separate file saved as a vector, the second column is the magnitude and the third column is the phase. I want to convert the magnitude and phase to compelx form for a set of frequency values, but when I try to do it for every frequency value it results in a single impedance value which is not what I want. This is what my code looks like right now. My issue is with the second for loop.
%Frequency from scan
Sweep;
for k=2:1:50
F(:,k)
s=2*pi*F*i;
end
%Impedance from scan, converted to complex
for j=1:1:49
Zp=Zp(j,2)*cos(Zp(j,3))+i*Zp(j,2)*cos(Zp(j,3))
end
%Line Impedance Calculations
LineImpedanceCalculation;
%Impedance Matrix Formulation
num6=0*F;
den6=1;
sys6=num6/den6;
num7=0*F;
den7=1;
sys7=num7/den7;
%Node 1
Z11=Zp+sys1+sys3
Z12=sys1+sys6+sys7
Z13=sys3+sys6+sys7
%Node 2
Z21=sys1+sys6+sys7
Z22=Zp+sys2+sys1
Z23=sys2+sys6+sys7
%Node 2
Z31=sys3+sys6+sys7;
Z32=sys2+sys6+sys7;
Z33=Zp+sys2+sys1;
%Final Impedance Matrix
Zmat = [Z11; Z21; Z31]
%Admittance Matrix and Eigenvalues
Ymat = inv(Zmat)
X=eig(Ymat)

採用された回答

David Hill
David Hill 2020 年 6 月 4 日
No loop needed.
[a,b]=pol2cart(Zp(:,3),Zp(:,2));
Zp=a+b.*i;
  2 件のコメント
Julia Hariharan
Julia Hariharan 2020 年 6 月 4 日
Thank you! I will try this now and let you know if it works.
Julia Hariharan
Julia Hariharan 2020 年 6 月 4 日
That worked! I have some other issues with my code, but this one is resolved - thanks!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeAntenna and Array Analysis についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by