matlab的setfield函数是给结构数组的字段指定值的。有以下两种调用方式:
s = setfield(s,'field',value)
s = setfield(s,{sIndx1,...,sIndxM},'field',{fIndx1,...,fIndxN},value)
第一种就不说了,第二种先看一个程序:
grades = [];
level = 5;
semester = 'Fall';
subject = 'Math';
student = 'John_Doe';
fieldnames = {semester subject student}
newGrades_Doe = [85, 89, 76, 93, 85, 91, 68, 84, 95, 73];
grades = setfield(grades, {level}, ...
fieldnames{:}, {10, 21:30}, ...
newGrades_Doe);
grades = setfield(grades, {level}, fieldnames{:}, {10,':'}, []);
这个是啥意思呢?看得有点懵逼。 结构体标
1x5struct
就是说这个结构体有5个记录,
setfield(grades, {level},fieldnames{:}, {10, 21:30}, newGrades_Doe);
就是说让结构数组grades的第5(level)个记录的“Fall”字段的“Math”字段的“John_Doe”字段(fieldnames{:})的那个值的第10行的21列到30列赋值为[85, 89, 76, 93, 85, 91, 68, 84, 95, 73](newGrades_Doe)。这是个结构体的层层嵌套。输入:
grades(level).(semester).(subject).(student)(10, 21:30)
就能返回“newGrades_Doe”,即:
ans =
85 89 76 93 85 91 68 84 95 73
那么这里的元胞数组“fieldnames{:}”怎么理解呢?其实就是逗号隔开的不同元素而已,也就是说:
setfield(grades, {level},fieldnames{:}, {10, 21:30}, newGrades_Doe);
setfield(grades, {level},fieldnames{1},fieldnames{2},fieldnames{3}, {10, 21:30}, newGrades_Doe);
grades = setfield(grades, {level}, fieldnames{:}, {10,’:’}, []);就是将赋值的那几个数所在的那一行去掉。matlab中没有的东西,你再赋值就会强制产生这个东西。有的东西,赋空就会去掉。
matlab的setfield函数是给结构数组的字段指定值的。有以下两种调用方式:s = setfield(s,'field',value)s = setfield(s,{sIndx1,...,sIndxM},'field',{fIndx1,...,fIndxN},value)第一种就不说了,第二种先看一个程序:grades = [];level = 5;semester = 'Fall';
char
函数
:ASCLL码转换成字符
eval
函数
:把字符串内容作为对应的
MATLAB
语句来执行
exist
函数
:检查变量在工作空间
中
是否存在,若存在则结果为1,否则为0
find
函数
:找出向量或矩阵
中
元素的位置
int2str
函数
:将整数转换成字符串
isempt...
1、ThinkPHP
中
的比较特殊连贯操作
如果要更新某个字段可以用
setField
方法,比如M('user')->where('id=1')->
setField
('username','ThinkPHP');这样子就只更新了username字段
如果要对某个字段增加或者减少某个数值,可以用 setInc(字段名,增加数值默认为1),setDec(字段名,减少数值默认为1);...
void Food(struct SHE *head);
int Move(struct SHE *head);
int Panduan(struct SHE *head, int x, int y);
struct SHE *Link(struct SHE *head);
void FreeShe(struct SHE *head);
void Gameover(void);
void Huitu(struct SHE *head);
int Fx, Fy; //食物的位置
int fen; //得分
int fang; //方向参数
int Tx, Ty;
//构造蛇身
struct SHE
int x;
int y;
struct SHE *next;
int main(void)
struct SHE *head = NULL;
int temp;
int times = TIME;
char m;
fen = 0;
fang = 2;
temp = fen;
times = TIME;
head = NULL;
head = (struct SHE *)malloc(sizeof(struct SHE));
head -> x = 40;
head -> y = 13;
head -> next = NULL;
Food(head);
while (1)
Huitu(head);
Sleep(times);
if (0 == Move(head))
FreeShe(head);
Gameover();
break;
if (temp < fen)
Food(head);
temp = fen;
if (times > 50)
times -=10;
else if (times > 20)
times -=1;
Gotoxy(19,21);
printf("是否继续?Y/N:");
scanf(" %c", &m);
system("cls");
} while (m != 'Y' && m != 'y' && m != 'n' && m != 'N');
} while (m == 'Y' || m == 'y');
return 0;
void Huitu(struct SHE *head)
int flag = 1;
while (head != NULL)
Gotoxy(head -> x, head -> y);
if (flag == 1)
printf("□");
else if (flag == 2)
printf("■");
Gotoxy(Tx, Ty);
printf(" ");
flag++;
head = head -> next;
//用于光标的移动
void Gotoxy(int x, int y)
COORD coord;
coord.X = x;
coord.Y = y;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
//食物位置构造
void Food(struct SHE *head)
int flag = 0;
struct SHE *pr = head;
srand(GetTickCount()); //基于毫秒级的随机数产生办法,需头文件winbase.h, windows中设计程序可以用windows.h
Fx = (rand()%40) * 2;
Fy = (rand()%12) * 2;
flag = 0;
pr = head;
while (pr != NULL) //防止食物位置与蛇形重合
if (pr -> x == Fx && pr -> y == Fy)
flag = 1;
break;
pr = pr -> next;
} while (flag == 1);
Gotoxy(Fx, Fy);
printf("■");
//用于蛇的移动
int Move(struct SHE *head)
char op;
int tox, toy, flag, temp;
if (kbhit()) //kbhit函数用于检查当前是否有键盘输入,若有则返回一个非0值,否则返回0,需头文件conio.h
op = getch();
switch (op)
case 'w':
if (fang != 3)
fang = 1;
break;
case 'd':
if (fang != 4)
fang = 2;
break;
case 's':
if (fang != 1)
fang = 3;
break;
case 'a':
if (fang != 2)
fang = 4;
break;
default:
break;
switch (fang)
case 1:
toy = (head -> y) - 1;
tox = (head -> x);
break;
case 2:
tox = (head -> x) + 2;
toy = (head -> y);
break;
case 3:
toy = (head -> y) + 1;
tox = (head -> x);
break;
case 4:
tox = (head -> x) - 2;
toy = (head -> y);
break;
default:
break;
flag = Panduan(head, tox, toy);
if (flag == 0)
return 0; //game over
else if (flag == 1)
head = Link(head);
fen++;
while (head != NULL)
temp = head -> x;
head -> x = tox;
tox = temp;
temp = head -> y;
head -> y = toy;
toy = temp;
head = head -> next;
return 1;
//用于食物与失败条件的判断
int Panduan(struct SHE *head, int x, int y)
int flag = 1;
if (x < 0 || x > HENG - 1 || y < 0 || y > SHU - 1)
return 0; //撞墙
while (head != NULL)
if (head -> x == x && head -> y == y && flag != 1)
return 0; //咬到自己
flag++;
if (head -> next == NULL)
Tx = head -> x;
Ty = head -> y;
head = head -> next;
if (x == Fx && y == Fy)
return 1;//有食物
return 2;//无异常
驱动方腔流SIMPLE方法
ANSYS_xiaobai:
驱动方腔流SIMPLE方法
ANSYS_xiaobai: