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

KSSV
KSSV 2017년 2월 17일
편집: KSSV 2017년 2월 17일
Giving the data would help us to help you..

댓글을 달려면 로그인하십시오.

답변 (1개)

KSSV
KSSV 2017년 2월 17일

0 개 추천

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')

카테고리

태그

질문:

2017년 2월 17일

답변:

2017년 2월 17일

Community Treasure Hunt

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

Start Hunting!

Translated by