Get the window data(lamda,flux, true) from a center point and the window width

49 篇文章 0 订阅
17 篇文章 2 订阅

Function:

function [lamda_win, flux_win] = show_window(lamda_cent, w_win, lamda, flux, flag_plot)
%Date:Dec 27,2011
%Author:shizhixin
%Email:szhixin@gmail.com
%Blog:http://blog.csdn.net/shizhixin
%Function get the window data(lamda,flux, true) from a center point and the window width.
%note the lamda is a sorted array and w_win should be a postive number.
%the postion of lamda_cent should be in [w_win+1,dim_lamda-w_win]
%EX Input:
% lamda = [1:20];
% flux = [50*sin((lamda*pi)/2)];
% subplot(1,2,1);
% plot(lamda, flux);
% lamda_cent = 10;
% w_win = 2;
% subplot(1,2,2);
% [lamda_win, flux_win] = show_window(lamda_cent, w_win, lamda, flux, true);
%Output:
%lamda_win = 8     9    10    11    12
%flux_win =  1.0e-014 *
%   -0.0490    0.0551   -0.0612    0.2450   -0.0735

%test the dim of lamda and flux
dim_lamda = length(lamda);
dim_flux = length(flux);
if dim_lamda ~= dim_flux
    disp 'the dim of lamda and flux is inconsistent!'
    return
end

%get the position of lamda_cent
pos_cent = 1;
for i=1:dim_lamda
    if lamda_cent >= lamda(i)
        pos_cent = i;
    end
end

%test the window boundary
if pos_cent <= w_win or pos_cent > dim_lamda-w_win
    disp 'the window is out of boundary!'
    return;
end

lamda_win = [lamda((pos_cent-w_win):(pos_cent+w_win))];
flux_win = [flux((pos_cent-w_win):(pos_cent+w_win))];

if flag_plot   
    %plot center line
    min_flux = min(flux_win);
    max_flux = max(flux_win);
    plot([lamda_cent:lamda_cent],[min_flux:5:max_flux],'r--');
    hold on
    plot(lamda_win, flux_win);
    title_name = sprintf('%s%d%s%d','lamda\_center:',lamda_cent, ', win\_width:', w_win);
    title(title_name);
end

end

Test:
>>  lamda = [1:20];
 flux = [50*sin((lamda*pi)/2)];
 subplot(1,2,1);
 plot(lamda, flux);
 lamda_cent = 10;
 w_win = 2;
 subplot(1,2,2);
 [lamda_win, flux_win] = show_window(lamda_cent, w_win, lamda, flux, true);

Figure:



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值