How can I resolve the objective function issue?

This is my code:
%% Variable
a_cor_width = 0.2e-9; % Auto-correlation width
N_def = 200/(a_cor_width*10^9); % 200e-9 means bandwidth, As reference
lambda_def = linspace(1400e-9, 1600e-9, N_def);

%% Random transmission matrix generation
M = 20; % Sampling channel >> Should be matrix
T_def = rand(M,N_def);
N = 5000; % Spectral pixel >> Should be matrix
lambda = linspace(1400e-9, 1600e-9, N);

T = spline(lambda_def, T_def, lambda);

for i=1:M
for j=1:N
if T(i,j) > 1
T(i,j) = 1;
elseif T(i,j) < 0
T(i,j) = 0;

% plot(lambda, T(1,:), lambda, T(2,:))

%% Reconstruction using cvx
delta_lambda = 200e-9/N;
ref_wavelength = lambda(3751); % 3751은 대충 1550
second_wavelength = lambda(3751+2);

input_spectrum = zeros(N, 1);
for i=1:N
if i==3751 | i==3751+2
input_spectrum(i) = 1;
input_spectrum(i) = 0;

output_I = T * input_spectrum;

variable x(N, 1)
minimize( abs(output_I - T*x) )

In this case, it gives the error, “Your objective function is not a scalar”. What can I do to resolve this problem?

The objective function as written is a vector. It must evaluate to s scalar. It is your problem, so you need to figure out what the correct fix is. For instance, applying sum would convert it to a scalar, but I’m not saying that is the “correct” thing to do.

I haven’;t looked at things closely enough to see whether the very small magnitude numbers used in some places might cause numerical difficulties die to bad numerical scaling.