Error with vectors not being the same length
Show older comments
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
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.
Accepted Answer
More Answers (0)
Categories
Find more on Axes Appearance in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!