calling function output variable names from a defined vector
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
i am defining very simple constraints function as below:
function[c_1 c_2 c_3] = nlcon(m)
c_1 = -0.875 + m(1) - m(2) + 1.75
c_2 = -1.75 - m(1) + 2*m(2) - m(3)
c_3 = -0.875 - m(2) + m(3) + 1.75
end
but instead of inserting the output variables manually (c1, c_2, c_3), i would like to define a set containing a variable number of constraints and i want to call the output variables from this sit. for example :
function [c] = const(m);
for i=1:3;
if i ==1;
c(i) = -0.875 + m(i) - m(i+1) + 1.75;
elseif i == 3;
c(i) = -0.875 - m(i-1) + m(i) + 1.75;
else
c(i) = -1.75 - m(i-1) + 2*m(i) - m(i+1);
end
end
but i get a wrong definition, any help?
then i tried to include that in the out
0 Kommentare
Antworten (1)
David Hill
am 28 Sep. 2020
Make sure you are saving the function as a code file (hit new function and enter and save the function there...not the command line)
Siehe auch
Kategorien
Mehr zu Logical finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!