主要内容:
1.Advanced 2D plots
2.Color space
3.3D plots
Exercise
• Plot a function: 𝑓(𝑡) = sin(𝜋𝑡2/4)
• Add the points sampled at 5 Hz using stem()
这个需要去了解一下stem()函数的用法,关系到横坐标轴的刻度范围
贴上自己写的代码:
t1 = linspace(0, 10, 51)'; % 采样频率为5Hz即1秒钟采样5次,0-10总共10秒钟,那么应该采样50次,即n=51;
t2 = linspace(0, 10, 1000);
y1 = sin(pi*(t1.^2)/4);
y2 = sin(pi*(t2.^2)/4);
stem(t1, y1);
hold on
plot(t2, y2); % 绘制出f(t)准确的波形图
Exercise
plot a wait sign
% Exercise
% plot a wait sign
t = (0:1:3)*pi/2;
x = sin(t);
y = cos(t);
h = fill(x, y, 'y');
axis square off;
text(0,0,'WAIT', 'Color','k', 'Fontsize',65,...
'Fontweight','bold', 'HorizontalAlignment','center');
set(h, 'Linewidth', 3);
绘制bar chart来展示2012奥运会获得奖牌最多的前五个国家的奖牌情况
% Exercise
G = [46 38 29 24 13];
S = [29 27 17 26 8];
B = [29 23 19 32 7];
h = bar(1:5, [G' S' B']);
title('Medal count for top 5 countries in 2012 Olympics');
xlabel('Country');
ylabel('Number of medals');
legend('Gold', 'Silver', 'Bronze');
set(gca, 'XTickLabel',{'USA','CHN','GBR','RUS','KOR'});
% 以下两种对bar chart颜色设置的方法都可以
% 方法一
% set(h(1), 'FaceColor', [204, 204,0]/255);
% set(h(2), 'FaceColor', [102, 102, 102]/255);
% set(h(3), 'FaceColor', [102, 51, 0]/255);
% 方法二
h(1).FaceColor = [204, 204,0]/255;
h(2).FaceColor = [102, 102, 102]/255;
h(3).FaceColor = [102, 51, 0]/255;
这个地方有些疑问,MATLAB官方文档里面说的16进制颜色代码我在使用的时候会报错
我的用法:
set(h(1), 'FaceColor', '#cccc00');
或者
h(1).FaceColor = '#cccc00';
按照官方文档里面的介绍,上述应该是可以使用的用法,但是我这样用的时候报错了
报错是:设置 'Bar' 的 'FaceColor' 属性时: 指定的字符串为无效的颜色值。
不知道是不是的MATLAB版本的问题,我的是MATLAB R2016a的版本
Exercise
• Create a custom green color map such that the
output of the script below looks like:
这一题的答案PPT上面似乎已经给出来了?
代码:
x = [1:10; 3:12; 5:14];
imagesc(x);
colorbar;
map = zeros(256, 3);
map(:, 2) = (0:255)/255;
colormap(map);
Exercise
• Combine the contour techniques to generate a
figure as shown below
代码:
x = -3.5:0.2:3.5;
y = -3.5:0.2:3.5;
[x, y] = meshgrid(x, y);
z = x.*exp(-x.^2-y.^2);
[c, h] = contourf(z, (-0.4:0.05:0.4));
clabel(c,h); % 标记
axis square;
colormap(jet);
这个画出来的图和PPT上的差不太多,就是很奇怪为啥左边最中间的那一部分是白色的而不是深蓝色。
好像有些题没弄上来,整理.m文件的时候发现有的图可能没整理,应该是太简单的就没做记录,就这样吧,,,,,,
弄些图博客看起来似乎高大上一点呢。。。。。。