matlab - 试图将 8 个数字放入 2 个窗口中
问题描述
x = [1 3 4 6 9];
y = x + 3;
stem(x); xlabel('My x axis'); ylabel('My y axis'); title('No title --:)');
grid on;
hold on;
stem(y);
我有 8 个使用这种格式制作的图表,我试图让它们出现在 2 个窗口中,每个窗口有 4 个图表,当我尝试使用 subplot 制作一个新文件时,这些图表看起来完全不同。我究竟做错了什么?
图 1 是正确的图 图 2 是我试图将其放入子图中
x = [1 3 4 6 9];
y = x + 3;
subplot(2,2,1), plot(x,y)
解决方案
你需要2个循环。一个循环用于数字,另一个循环用于每个图中的子图:
for i = 1:2
figure; % this creates a separate figure
for j=1:4
subplot(2,2,j);
x = randi(10, 1, 4);
y = x + 3;
stem(x); xlabel('My x axis'); ylabel('My y axis'); title('No title');
grid on;
hold on;
stem(y);
end
end
推荐阅读
- kubernetes - 检查 etcd 运行状况时超出上下文截止日期
- python - 尝试使用 BeautifulSoup 查找 div 时,Webscraping 不返回任何内容
- django - 聚合输入的多个实例的自定义 Django 模型表单字段
- javascript - JavaScript 函数计算器
- python - 浅拷贝操作混乱
- qt - QWindow::showMinimized() 不起作用,错误?
- android - 在 nativescript-vue 中混合全局和框架导航不起作用
- c# - 在winforms中将复选框插入工具条时出现问题
- python - lxml无法导入etree包
- javascript - Axios 无法在请求拦截器中添加/更新标头