MATLAB文件数据绘图及相关应用
1. 文件数据绘图概述
在数据分析和可视化中,从文件读取数据并进行绘图是常见的操作。这通常需要了解文件的格式,以便正确读取和处理数据。下面通过几个具体的例子来详细介绍如何在MATLAB中实现这一操作。
1.1 示例一:公司两个部门的销售数据绘图
假设一家公司有两个部门A和B,文件 ab11.dat 包含了2011年每个季度这两个部门的销售数据(以百万为单位)。文件内容格式如下:
A5.2B6.4
A3.2B5.5
A4.4B4.3
A4.5B2.2
以下是读取这些数据并绘制柱状图的脚本 plotdivab.m :
% Reads sales figures for 2 divisions of a company one
% line at a time as strings, and plots the data
fid = fopen('ab11.dat');
if fid == -1
disp('File open not successful')
else
for i = 1:4
% Every line is of the form A#B#; this separates
% the characters and converts the #'s to actual
% numbers
超级会员免费看
订阅专栏 解锁全文
466

被折叠的 条评论
为什么被折叠?



