Error with vectors not being the same length

4 views (last 30 days)
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 Comment
Rik
Rik on 29 Sep 2018
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.

Sign in to comment.

Accepted Answer

Star Strider
Star Strider on 29 Sep 2018
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 Comments
Michael Valero
Michael Valero on 29 Sep 2018
My Mistake, removed 42 from the range for f_actual. Thank you.
Star Strider
Star Strider on 29 Sep 2018
As always, my pleasure.
I probably should have specifically mentioned that I had to remove 42 from it when I posted it.

Sign in to comment.

More Answers (0)

Categories

Find more on Axes Appearance in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!