Error with vectors not being the same length

15 ビュー (過去 30 日間)
Michael Valero
Michael Valero 2018 年 9 月 29 日
コメント済み: Star Strider 2018 年 9 月 29 日
I've been playing with this for a hot minute. I don't know what I am doing wrong in getting this graph correctly. I have an error on line 25 where the vectors are not the same length, and I just tried using linspace for the length. Not sure if I am using the fix correctly for the right identified length.
%%fe = [42 100 1000 5000 10000 50000 100000 500000 1000000 5000000];
fe = linspace(0, 0.001, length(f));
f = logspace(1,8,1000);
we = 2*pi*fe;
w = 2*pi*f;
L = 3.5E-8;
R = 1E6;
C = 1E-12;
Zce = j*we*L+(R./(1+j*we*C*R));
Zc = j*w*L+(R./(1+j*w*C*R));
Zmag = abs(Zc);
Zmage = abs(Zce);
Zang = angle(Zc)*180/pi;
Zange = angle(Zce)*180/pi;
Zmag_actual = [1E6 1E6 1E6 1E6 1E6 1E6 1E6 967E3 872E3];
Zang_actual = [0 -0.03 -0.02 -.1 -0.36 -1.68 -3.58 -16.5 -29.97];
subplot(2,1,1)
loglog(f,Zmag);
hold on;
loglog(fe,Zmage,'rx');
loglog(fe,Zmag_actual,'bo');
title('Resistor Test');
ylabel('Impedance Magnitude');
xlabel('Frequency (HZ)');
hold off;
subplot(2,1,2)
semilogx(f,Zang);
hold on;
semilogx(fe,Zange,'rx');
semilogx(fe,Zang_actual,'bo');
ylim([-100 100]);
ylabel('Impedance Angle (degrees)');
xlabel('Frequency (HZ)');
hold off;
Thanks in advance.
  1 件のコメント
Rik
Rik 2018 年 9 月 29 日
Running this code (after switching the definitions for f and fe), I get an error on this line:
loglog(fe,Zmag_actual,'bo');
The error being that the vectors are not the same length.
If you look at the sizes of every variable here, you should notice that Zmag_actual is only 9 values long, instead of the 1000 that you are using for most other vectors. Even the hard-coded version of fe that you commented out doesn't work, because that has 10 elements.
I don't know what your goal is because you hard-coded some values and did not provide any comments whatsoever. That means I can't even guess the way in which I should correct your code.

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

採用された回答

Star Strider
Star Strider 2018 年 9 月 29 日
I suspect that what you want is to plot ‘Zmag_actual’ and ‘Zang_actual’ against (a slightly tweaked version of) your commented-out ‘fe’ vector, that I renamed ‘f_actual’:
f_actual = [100 1000 5000 10000 50000 100000 500000 1000000 5000000];
then in their respective subplot calls:
loglog(f_actual,Zmag_actual,'bo');
and:
semilogx(f_actual,Zang_actual,'bo');
that when plotted seem to be in the appropriate ranges.
Also, ‘fe’ does not seem to me to be defined correctly, at least with respect to its being defined as starting with 0. That is not going to work with a logarithmic x-axis.
  3 件のコメント
Michael Valero
Michael Valero 2018 年 9 月 29 日
My Mistake, removed 42 from the range for f_actual. Thank you.
Star Strider
Star Strider 2018 年 9 月 29 日
As always, my pleasure.
I probably should have specifically mentioned that I had to remove 42 from it when I posted it.

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

その他の回答 (0 件)

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by