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])

相关推荐
bu_shuo3 小时前
Simulink中的On Delay模块
matlab·simulink·on delay
元素之窗6 小时前
MATLAB 的输入与输出:一篇速查博客
开发语言·matlab·php
元素之窗8 小时前
MATLAB 的“面子工程”:一键切换数值显示风格 —— format 命令小记
开发语言·算法·matlab
软件算法开发8 小时前
基于GA遗传优化的5G微基站部署策略matlab仿真
5g·matlab·ga遗传优化·微基站部署
freexyn10 小时前
Matlab自学笔记六十九:多项式求值、求根、积分和求导
开发语言·笔记·matlab
机器学习之心10 小时前
MATLAB基于改进蜣螂优化算法的磨削参数低碳优化
算法·matlab·基于改进蜣螂优化算法·磨削参数低碳优化
轻微的风格艾丝凡1 天前
模型拆解--Analysis of a Linear Circuit
matlab·simulink·电力电子技术
996终结者1 天前
精通MATLAB中的数据标准化与归一化
matlab·数据处理·数据标准化
三维空间1 天前
MATLAB输入输出完全教程:input/disp/fprintf函数用法与实战
matlab
三维空间1 天前
MATLAB数组创建完全教程:直接赋值/linspace/zeros/ones/rand函数用法与实战
matlab