How to fix this error in interp1?
2 次查看(过去 30 天)
显示 更早的评论
this is my code, i want to zoom in the db from -5 to -1, there is a problem that error using interp1 X mush be a vector, could you please help me?
R = 1e3; % resistor value [Ohms]
C = 1e-6; % Capacitor value [Farads]
H = tf([R*C,0], [R*C,1]);
% plot a bode plot (3dB frequency should be at 1/RC = 1000 rads/sec.
[mag,phase,wout] = bode(H);
zoom y lim = [-5,-1]; % y-axis range for zoom in section
min max w zoom = interp1(20*log10(mag),wout,zoom y lim);
indexOfInterest = (wout > min(min max w zoom)) & (wout < max(min max w zoom));
plot(wout(indexOfInterest),20*log10(mag(indexOfInterest)));
2 个评论
回答(1 个)
Chunru
2021-11-16
编辑:Chunru
2021-11-17
R = 1e3; % resistor value [Ohms]
C = 1e-6; % Capacitor value [Farads]
H = tf([R*C,0], [R*C,1]);
% plot a bode plot (3dB frequency should be at 1/RC = 1000 rads/sec.
[mag,phase,wout] = bode(H);
wout = squeeze(wout);
mag = squeeze(mag);
plot(wout, 20*log10(mag), 'b:');
zoom_y_lim = (-5:.1:-1); % y-axis range for zoom in section
w_zoom = interp1(20*log10(mag), wout, zoom_y_lim);
whos
hold on
plot(w_zoom, zoom_y_lim, 'r-', 'Linewidth', 2);
ylim([-8 0])
xlim( [0 1]*1e4)
figure
semilogx(wout, 20*log10(mag), 'b'); grid on
ax = axes('Pos', [.4 .2 .4 .4], 'Box', 'on');
semilogx(w_zoom, zoom_y_lim); grid on
9 个评论
Chunru
2021-11-20
Let's assume that f_vec=[0 1 2 3 4 5 6 7]; F1=4.99; min(abs(f_vec-F1)) is to find the closest point in f_vec to F1. In this case, it is f_vec(6)=5 which is closest to 4.99. The whole statement of [~, i1]=min(abs(f_vec-F1)) will assign the index 6 to i1.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Plot Customization 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!