matlab 画图函数,文件的读写

matlab 画图函数,文件的读写

 

%读取excel数据并画图
A= xlsread('excel路径\excel名','sheet1','a3:b35');
[temp, col] = size(A);
plot(A(:,1),A(:,2:col));
xlabel('时间(s)');
legend('销量')


F=[160,120;159,110];
%那么讲该数据写入一个data文件是
filename='test.dat';
fid = fopen(filename,'w');
count = fwrite(fid,F,'uchar');
fclose(fid);

 


%读取txt文件
[filename path]=uigetfile('*.txt','please input you want to get file','test');
hectorload=[path filename];
x=load(hectorload);
x

 

%从txt文件中读取矩阵数据并画图
fidin=fopen('test2.txt');                               % 打开test2.txt文件             
fidout=fopen('mkmatlab.txt','w');                       % 创建MKMATLAB.txt文件
while ~feof(fidin)                                      % 判断是否为文件末尾               
   tline=fgetl(fidin);                                 % 从文件读行   
   %if double(tline(1))>=48&&double(tline(1))<=57     % 判断首字符是否是数值
   fprintf(fidout,'%s\n\n',tline);                  % 如果是数字行,把此行数据写入文件MKMATLAB.txt
   continue                                         % 如果是非数字继续下一次循环
   end
end
fclose(fidout);
MK=importdata('MKMATLAB.txt');      % 将生成的MKMATLAB.txt文件导入工作空间,变量名为MK,实际上它不显示出来

[temp, col] = size(MK);
plot(MK(:,1),MK(:,2:col),'*',MK(:,1),MK(:,2:col));

% 画图,标出纵坐标的值
x=[1,2,3,4,5];
y=[2,5,3,8,6];
plot(x,y,'*',x,y);

for i=1:5
 text(x(i),y(i),num2str(y(i)))
end
%图的叠加
hold on
% 矩阵的第一列为横坐标,其他列都为纵坐标,画图
X =[1,2,1;2,3,7;3,6,4]
[temp, col] = size(X);
plot(X(:,1),X(:,2:col),'*',X(:,1),X(:,2:col));
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值