Clear Filters
Clear Filters

Change in linprog.m output?

1 view (last 30 days)
Joel Miller
Joel Miller on 13 Aug 2018
Edited: Matt J on 14 Aug 2018
I use the following code to fit multiple data sets using linprog.m.
for k=1:nsets
b = [data(:,k)+2*noise; -data(:,k)+2*noise];
[fitpars(:,k), ~, flag(k)] = linprog(w,A,b,[],[],lb,ub,[],opts);
end
A solution is not found for each data set, so I save the exitflag. The code executes successfully in R2016b, but in R2018a I get the error message "Unable to perform the assignment because the size on the left side is 320-by-1 and the size on the right side is 0-by-0." whenever the exitflag does not equal 1. (fitpars(:,k) is size 320-by-1) In both R2016b and R2018a I use the default algorithms. Is there a way to get R2018a to provide output compatible with the output from R2016b?

Accepted Answer

Matt J
Matt J on 13 Aug 2018
Edited: Matt J on 13 Aug 2018
You should save to a cell array.
[fitpars{k}, ~, flag(k)] = linprog(w,A,b,[],[],lb,ub,[],opts);
It was just random luck that your original code ever worked. You cannot stick an empty result into the column of a non-empty matrix.
  11 Comments
Joel Miller
Joel Miller on 14 Aug 2018
Same here, and iters = 0.
Matt J
Matt J on 14 Aug 2018
Edited: Matt J on 14 Aug 2018
OK, well I think that proves my earlier conjecture. There was never any guarantee, even in R2016b, that the output of linprog will be non-empty, so storing results to a cell array was always the only safe thing to do.

Sign in to comment.

More Answers (0)

Products


Release

R2018a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!