Do you see that Xhat takes on only the values [8, 10, 12]?
Question
Hello everyone! I'm trying to perform a Bayesian optimization to find the best hyperparameters for a deep neural network and I want the variable MiniBatchSize to just have, in this case, three possible values: 8, 10, 12. I thought I could declare optVar as if it was an array interval = 8:2:12; optVar = optimizableVariable('MiniBatchSize', interval, 'Type', 'integer'); This code raises the following error: Error using optimizableVariable/checkRange 'Range' value must be a string array, a cell array of character vectors, or a numeric vector of length 2. Am I missing something? Is there another way to perform this?
Expert Answer
John Williams
PhD Expert
Answered Aug 14, 2026
Suppose X is an integer variable, that takes on only the values 1:5.
But what you want are non-integer levels of some parameter. For example, perhaps you want levels at [1.5, 3.5, 5.5, 7.5, 9.5]?
Inside your code, just write
Xhat = 2*X - 0.5;
Do you agree that Xhat takes on the desired levels?
They need not even be at all regular. Suppose you want levels at [2 3 5 7 11]? Inside your code, you might do this:
levels = [2 3 5 7 11]; Xhat = levels(X);
Clearly I could have chosen ANY levels there.
In your specific case, X is an integer variable that takes on the values 1:3. But you want it to take on the values [8 10 12]. Again, inside your code, write this:
Xhat = X*2 + 6;
100% Run Guarantee
3-Hour Fast-Track Delivery
Need a Custom Version or Complete Simulation for This Problem?
Our 500+ PhD engineers build, debug, and optimize working MATLAB scripts and Simulink (.slx) models tailored to your exact assignment rubrics with zero plagiarism.
Tested on MATLAB R2024b / R2026a
Turnitin 0% Plagiarism Report
Free 7-Day Revisions Guarantee
Have a different question? Ask here
Related deep learning Questions & Solutions
Browse All →
Explore similar technical troubleshooting questions and verified MATLAB solutions:
Ready-to-Run MATLAB & Simulink Projects
Browse All Projects →