Error with vectors not being the same length

조회 수: 5 (최근 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 CenterFile Exchange에서 Axes Appearance에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by