-1

我正在努力为我收集的数据拟合模型。在模型中,我确定最适合参与者数据的最佳参数值,然后调整并缩小查看窗口(范围)以获得更精确的参数值。我正在使用 linspace 生成新值来测试参与者数据。最初使用先前的改编我没有问题。一旦我编辑了我的脚本以包含一个条件“如果”部分以防止参数小于零,我遇到了“使用 linspace 的错误(第 22 行)输入必须是标量。如果我正确理解问题,因为我”我将向量而不是标量传递给 linspace 函数,但我不明白为什么现在会发生这种情况,而且我之前的改编不是这种情况。我假设它与“

“使用 linspace 时出错(第 22 行)输入必须是标量。”

“Range_Adjustment 错误(第 43 行)alphas = linspace(min_aro, max_aro,10);”

%Finds coordinates of optimal parameters for Condition 0 
[x0,y0] = find(all_SSD_cond0 == min(min(all_SSD_cond0)));
 
%%% Identifies alpha and beta values that correspond to the coordinates for
%%% optimal parameters%%%
alphas(y0) 
betas(x0)  
 
  
%%%% Adjusts range for Condition 0 %%%
 
%Adjusts Alpha Range%
alpha_range = alpha_range.*0.7 % Decreases alpha range by 30%
min_aro = alphas(y0)-(alpha_range./(0.5)) %Creates optimized minimum of alpha range half distance away from identified optimal alpha value from previous iteration. 
if min_aro < 0 % Conditional statement if minimum alpha range is less than zero min_aro = 0
    min_aro = 0
end
max_aro = alphas(y0)+(alpha_range./(0.5)) %Creates optimized maximum value of alpha range half distance away from identified optimal alpha value from previous iteration.
 
%Adjusts Beta Range%
beta_range = beta_range.*0.7;% Decreases beta range by 30%
min_bro = betas(x0)-(beta_range./(0.5)); %Creates optimized minimum of beta range half distance away from identified optimal beta value from previous iteration.
if min_bro < 0  % Conditional statement if minimum beta range is less than zero min_bro = 0
    min_bro = 0
end
max_bro = betas(x0)+(beta_range./(0.5)); %Creates optimized minimum of beta range half distance away from identified optimal beta value from previous iteration.
 
%%% Adjusts viewing frame and creates optimized alpha and beta parameters
%%% for fitting process%%%
alphas = linspace(min_aro, max_aro,10);
betas = linspace(min_bro, max_bro,10);
 
%alphas = linspace(alphas(y0)-(alpha_range./2), alphas(y0)+(alpha_range./2),10);
%betas = linspace(betas(x0)-(beta_range./2), betas(x0)+(beta_range./2),10);
4

1 回答 1

0

您需要更改您的代码,以便您保证x0并且y0每个仅包含一个索引。如果矩阵中有多个元素等于最小值,x0并且y0将是一直传播到 的数组linspace()

如何做到这一点取决于你想要什么行为,例如,如果你想要矩阵的第一个元素等于最小值,你可以这样做:

[x0, y0] = find(all_SSD_cond0 == min(min(all_SSD_cond0)), 1, 'first');

于 2021-04-27T08:30:11.223 回答