calling function output variable names from a defined vector
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Sherif Abdelghany
el 28 de Sept. de 2020
Comentada: Sherif Abdelghany
el 28 de Sept. de 2020
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 comentarios
Respuestas (1)
David Hill
el 28 de Sept. de 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)
Ver también
Categorías
Más información sobre Logical en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!