1

I'm working on fitting a model to data I have collected. Within the model, I identify the optimal parameter values that best fit participant data then adjust and reduce the viewing window (range) to get more precise parameter values. I'm using linspace to generate new values to test against the participant data. Initially using a prior adaptation I had no issues. Once I edited my script to include a conditional "If" section to prevent parameters from being less than zero, I encountered the "Error using linspace (line 22) Inputs must be scalar. If I'm understanding the problem correctly its becuase I'm passing a vector into the linspace function instead of a scalar, but I don't understand why that is occuring now and was not the case with my previous adaptation. I'm assuming it has to do with the " if min_ < 0....." addition. Could someone help me to better understand where I'm making my error and how to correct this?

"Error using linspace (line 22) Inputs must be scalars."

"Error in Range_Adjustment (line 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);
  • What are the values of `max` and `min` `aro` and `bro`? – Pranav Hosangadi Apr 23 '21 at 19:41
  • It's impossible to tell you where things go wrong, because we don't know the values of most of these variables. Please read [mre], then [edit] your question accordingly. The `if ...<0` step doesn't have any influence in this. Likely you get different results because your inputs are different. – Cris Luengo Apr 23 '21 at 19:41
  • This code is hard to read. For example, what does `alphas(x0)` or `betas(y0)` do? They don't return anything, and so something behind the scenes must be happening. – Donna Apr 24 '21 at 15:48
  • I could post the whole script, but I felt it may be unnecessary without the the data as well. I could probably take out alphas(y0) and betas(x0) where it is posted by itself. The alphas(y0) and betas(x0) is the alpha parameter and beta parameter values used to to generate the model learning curve that best fits the participant data. – Ryan Gallagher Apr 24 '21 at 20:35

1 Answers1

1

You need to change your code so that you guarantee that x0 and y0 only contain one index each. If there are multiple elements of the matrix that equal the minimum value, x0 and y0 will be arrays that propagate all the way to linspace().

How to do it depends on what behavior you want, if you for example want the first element of the matrix that equals the minimum value you can do this:

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