There's a bug in MATLAB: if np is equal to 1. The request to the optimizer should be "parameter": [13.0], but it is "parameter": [, 13.0] instead (extra comma in the beginning).
To Solve
Replace consume with:
function out = consume(o, p)
if length(p) > 1
p_formatted_str = sprintf('%f, ', p(1:end-1))
else
p_formatted_str = '';
end
req_str = sprintf('{"parameter":[%s %f]}', p_formatted_str, p(end))
fwrite(o.udp_connection, req_str);
json_response = fread(o.udp_connection, 50000, 'char')
json_response = char(json_response')
out = jsondecode(json_response);
end
Describe the bug
There's a bug in MATLAB: if
np
is equal to 1. The request to the optimizer should be"parameter": [13.0]
, but it is"parameter": [, 13.0]
instead (extra comma in the beginning).To Solve
Replace
consume
with:I'll start a pull request later.