matlab基础操作(六)

36.结构数组嵌套:结构数组中结构的字段还可以是结构

>> student(2).course(1).title='Web Programming';

>> student(2).course(1).credits=2;

>> student(2).course(2).title='Numerical Method';

>> student(2).course(2).credits=3;

>> student(2).course

>> student(1).name='Newton';%修改结构数组变量的字段值

>> student(1).name

37.cat函数:排列结构数组某字段的值

格式:cat(dim,structurefield),dim=1,竖排;dim=2,横排。

>> cat(1,student.scores)

>> cat(2,student.scores)

38.计算平均值(使用mean函数)

计算每次考试的平均值

>> average1=mean(cat(1,student.scores))

计算每个学生成绩的平均值

>> average2=mean(student(2).scores)

39.二维曲线绘图的基本操作

(1)plot(x),x为向量时,以该元素的下标为横坐标、元素值为纵坐标绘出曲线。

(2)plot(x,y),x、y为同维数组时,绘制以x、y元素为横纵坐标的曲线。

(3)plot(x1,y1,x2,y2,...),绘制以x1为横坐标、y1为纵坐标的曲线1,以x2为横坐标、y2为纵坐标的曲线2,等等。其中x为横坐标,y为纵坐标,绘

制y=f(x)函数曲线。

Exam:在[0,2π]区间内,绘制曲线2e^-0.5xsin(2πx)。

>> x=0:pi/100:2*pi;

>> y=2*exp(-0.5*x).*sin(2*pi*x);

>> plot(x,y)

Exam:绘制曲线x=tcos(3t)、y=t(sint)^2,-π≤t≤π。

>> t=-pi:pi/100:pi;

>> x=t.*cos(3*t);

>> y=t.*sin(t).^2;

>> plot(x,y)

40.绘制复杂曲线

Exam:用图形表示连续调制波形及其包络线。

>> t=(0:pi/100:pi)';%长度为101的时间采样列向量

>> y1=sin(t)*[1,-1];%包络线函数值,是(101*2)的矩阵

>> y2=sin(t).*sin(9*t);%长度为101的调制波列向量

>> t3=pi*(0:9)/9;

>> y3=sin(t3).*sin(9*t3);

>> plot(t,y1,'r',t,y2,'b',t3,y3,'bo')

>> axis([0,pi,-1,1])

相关推荐
机器学习之心13 小时前
机器人路径规划 | 基于极光PLO优化算法的机器人三维路径规划Matlab代码
算法·matlab·机器人·三维路径规划
IT猿手16 小时前
2025最新智能优化算法:改进型雪雁算法(Improved Snow Geese Algorithm, ISGA)求解23个经典函数测试集,MATLAB
数据库·人工智能·算法·机器学习·matlab
studyer_domi1 天前
matlab质子磁力仪传感器线圈参数绘图
人工智能·matlab
青橘MATLAB学习2 天前
模糊综合评价法:原理、步骤与MATLAB实现
开发语言·算法·数学建模·matlab·分类
studyer_domi2 天前
matlab 三维时频图绘制
开发语言·matlab
studyer_domi2 天前
matlab飞行姿态pid控制
matlab
Matlab仿真实验室2 天前
基于Matlab实现信道估计仿真(源码)
开发语言·matlab·信道估计仿真
studyer_domi2 天前
matlab 汽车abs的pid控制仿真
开发语言·matlab·汽车
studyer_domi2 天前
matlab 汽车abs的模糊pid和pid控制仿真
开发语言·matlab·汽车
freexyn2 天前
Matlab自学笔记四十七:如何把日期时间型数据作为横坐标进行绘图
开发语言·笔记·matlab