bandwidth from 2D array
이전 댓글 표시
Hello,i have a 2D array of numbers, i need to take the peak value which always located at the same X=0 point and subtracts 3 and find the two points(positive X-axes and negative X axes) in this table which are the closest to these values.
for example if my value at x=0 is 7 then i need to find the two places int the Y axes which are closest to 4.
if if we have (-30,4.1) and (+32,4.3) then the bandwidth 30+32 is 62 i thought of running two parallel "for" one for positive axes one for negative axes and taking the closest point on each side by checking iteratively.
is there an easier way?
Thanks
댓글 수: 1
답변 (1개)
KSSV
2017년 2월 17일
clc; clear all ;
y = 2*sin(linspace(0,pi))' ;
x = [1:length(y)]' ;
p = [x y] ;
%%get maximum
[val,idx] = max(y) ;
% substract and add a value
dw = 0.2 ; % value to be substracted
y0 = val-dw ;
% get the nearest values
id = find(abs(y-y0)-dw <= 10^-3) ;
idx0 = id(1) ; idx1 = id(end) ;
% required points
p0 = [x(idx0) y(idx0)] ;
p1 = [x(idx1) y(idx1)] ;
% Bandwidth
BW = abs(x(idx0)-x(idx1)) ;
% plot
figure
hold on
plot(x,y,'r') ;
plot(x(idx), y(idx),'Or')
plot(p0(1),p0(2),'*g')
plot(p1(1),p1(2),'*b')
카테고리
도움말 센터 및 File Exchange에서 Multirate Signal Processing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!