table1 =table(id,startTime,spendTime,cpuStation,stackStation);%添加变量:node.age=[1:1:100]'
[row,col]=size(table1);
node =table2struct(table1(1,:),'ToScalar',true)for i =2:row
node(i)=table2struct(table1(i,:),'ToScalar',true);
end
3.3 struct转为node
table2 =struct2table(node);
四、其他常用的
4.1 判断数据的类型
class(data)
4.2 非线性规划和结构体结合
% min F(X)% s.t
% AX <= b
% AeqX = beq
%G(x)<=0%Ceq(X)=0% VLB <= X <= VUB
clear
clc
x0 =[-2-2-2--2];%初始值!
Aeq =[1111];
beq =[4];
VLB =[-2-2-2-2];
VUB =[2222];
b =3;
student =struct("name","jack","age",23);%[x, fval]=fmincon(@fun3, x0, A, b, Aeq, beq, VLB, VUB)%两种都可以,后者可以传递参数
[x,fval]=fmincon(@(x)fun3(x,student), x0,[],[], Aeq, beq, VLB, VUB)
function f =fun3(x,student)
f =x(1)+x(2)+x(3)-x(4)+student.age;
end