I understand that you want to find the minimum variance portfolio. You can do this in two ways.
1) The easiest way is to use the Portfolio object. Assume that you have the mean (mu) and covariance (Sigma) of the returns. Then, you can find the minimum variance portfolio like this:
p = Portfolio('AssetCovar',Sigma,'AssetMean',mu);
p = setDefaultConstraints(p);
w = p.estimateFrontierLimits('min');
Here ( https://www.mathworks.com/help/finance/when-to-use-portfolio-over-problem-based-framework.html ) you can find a list of the portfolio optimization problems that can be solved using the Portfolio object.
2) The second way is to write an optimization problem and solve it:
prob = optimproblem('ObjectiveSense','minimize');
x = optimvar('x',nAssets,1,'LowerBound',0);
prob.Objective = x'*Sigma*x;
prob.Constraints.sumToTau = sum(x) == 1;
Hope this helps!