写论文第五天:参数扫描法

这篇博客介绍了MATLAB中用于参数扫描的parameterSweep函数,以及并行计算的parfor语法。parameterSweep函数通过输入函数句柄和参数范围进行扫描,返回最优结果及对应参数。parfor则用于并行执行循环任务,提高计算效率,文中展示了其与普通for循环的区别。此外,还提及了size函数的不同用法和RSI指标的计算方法。
摘要由CSDN通过智能技术生成

1.parameterSweep函数

[respmax,varmax,resp,var] = parameterSweep(fun,range)

输出的4个变量依次是最优结果(比如最大夏普比例),最优结果对应的参数组合,所有扫描结果以及所有的参数组合。

输入两个变量,第一个是一个指向被扫描函数的function handle,第二个是一个cell类型,可以包含多个参数的范围。



>> type parameterSweep

function [respmax,varmax,resp,var] = parameterSweep(fun,range)
%PARAMETERSWEEP performs a parameters sweep for a given function
%   RESPMAX = PARAMETERSWEEP(FUN,RANGE) takes as input a function handle in
%   FUN and the range of allowable values for inputs in RANGE.
%
%   FUN is a function handle that accepts one input and returns one output,
%   F = FUN(X), where X is an array of size N x M.  N is the number of
%   observations (rows) and M is the number of variables (columns).  F is
%   the response of size N x 1, a column vector;
%
%   RANGE is a cell array of length M that contains a vector of ranges for
%   each variable.
%
%   [RESPMAX,VARMAX,RESP,VAR] = PARAMETERSWEEP(FUN,RANGE) returns the
%   maximum response value in RESPMAX, the location of the maximum value in
%   VARMAX, an N-D array of the response values in RESP, and and N-D array
%   where the size of the N-D array depends upon the values in RANGE.
%   NDGRID is used to generate the arrays.
%
%   Examples:
%   % Example 1: peaks function
%     range = {-3:0.1:3, -3:0.2:3};  % range of x and y variables
%     fun = @(x) deal( peaks(x(:,1),x(:,2)) ); % peaks as a function handle
%     [respmax,varmax,resp,var] = parameterSweep(fun,range);
%     surf(var{1},var{2},resp)
%     hold on, grid on
%     plot3(varmax(1),varmax(2),respmax,...
%         'MarkerFaceColor','k', 'MarkerEdgeColor','k',...
%         'Marker','pentagram', 'LineStyle','none',...
%         'MarkerSize',20, 'Color','k');
%     hold off
%     xlabel('x'),ylabel('y')
%     legend('Surface','Max Value','Location','NorthOutside')
%
%   See also ndgrid

%%
% Copyright 2010, The MathWorks, Inc.
% All rights reserved.

%% Check inputs
if nargin == 0
    example(1)
else
    %% Generate expression for ndgrid
    N = length(range);
    if N =&
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值