未定义的功能' yout'对于类型' double'的输入参数

时间:2014-10-09 17:13:41

标签: matlab simulink

我在Matlab中为液压阀建立模型(test1)。

当我尝试优化工具时,我收到以下错误:运行优化时出错。未定义的功能' yout'输入参数类型为' double'。

这是我使用的目标函数的代码:

function F  = obj_find_valve_param_a_max(x,Q_r)
% Objective function to find the maximum valve area parameter value
% Copyright 2010 MathWorks, Inc.

assignin('base','a_max', x);

% If necessary, reset parameterizaton to second option (table)
model = 'test1';
load_system(model);
blkpth = find_system(bdroot,'ClassName','valve_dir_4_way');
set_param(char(blkpth),'mdl_type','1');
sim(model);

k = [1 1 1 0.9 0.8 0.7 0.6 0.5 0.4 0.3 0.2];    % Weight multipliers
% Computing objective function
F = 0;
for j = 1:11
    F = F + k(j) * (yout(j) - Q_r(j))^2;
end
end

% EOF


% Script to find directional valve parameter a_max
% Copyright 2010 MathWorks, Inc.

% This script file invokes optimization process to find the orifice
% area at maximum opening for 4-way directional valve when the valve is
% modeled using the first parameterization option (linear relationship
% between control signal and orifice area).

% init_opening - vaalve initial openings [mm]
% A_leak - leakage area  [m^2]
% Q_r - vector of required flow rate at 11 valve displacements
% x0 - initial value for the only variable parameter: orifice maximum area

init_opening = -1;     % mm
A_leak = 1e-9;         % m^2

% Vector of required flow rates. Read out from plot on page 8 in 
% Eaton/Vickers Porportional Directional Valves catalog for KBFDG5V-10 valve
% Actual flow rates are determined at fixed instances of time by exporting
% flow rate measured at the external loop of the valve to the MATLAB
% workspace

Q_r = [0 0 52 150 248 346 450 540 625 670 700];

% Set initial value of the orifice maximum area
x0 = 4.8;           % [cm^2]

% Optimization
[x,fval,exitflag,output] = ...
    fminsearch(@obj_find_valve_param_a_max,x0, ...
    optimset('Tolx',1e-6,'Display','iter'),Q_r);

%bdclose all

如果我从第一个代码yout(j) - Q_r(j)中删除,则迭代成功完成。 请问有谁知道如何处理这个错误? 谢谢。

2 个答案:

答案 0 :(得分:0)

此错误表示MATLAB不知道如何处理对您的引用。如果你是一个变量(我猜这是你的意图)那么它必须是初始化才能被索引。这条线

  
yout(j) - Q_r(j)
  

是尝试索引数组的第j个元素。因此,你必须是一个长度至少为j的数组。但是,您的代码没有初始化变量,因此错误。

答案 1 :(得分:0)

您没有向我们展示您的模型test1,更重要的是,它是如何配置的。您需要在模型中具有根级出口块,并将模型配置为将输出保存到工作空间变量yout(有关如何执行此操作的详细信息,请参阅Data Import/Export Pane)。此外,您的脚本(我怀疑是从某些MathWorks材料中复制的......)假定yout长度为11.确保正确设置采样时间和/或抽取/输出选项以确保&# 39;是的。