怎样用matlab从txt文件中读取数据,每次只读取一行?

这样的一个u.txt文件,用matlab从中读取数据,每次只读取一行进行处理,然后继续...u.txt文件如下:
14 19 337 312
12 16 33 31
19 19 36 32
12 17 33 11
14 10 36 11
42 11 36 11
12 71 35 31
43 17 33 10
45 72 35 21

编写mymesh()函数:
function mymesh()
temdat=load('D:\test.txt');
if temdat== -1
('Error opening the file');
end
figure;
h=plot3(temdat(:,1),temdat(:,2),temdat(:,3));
set(h,'linestyle','none')
hold on;
grid on;
[x,y]=meshgrid(linspace(-150,150,500),linspace(-150,150,500));
z = griddata(temdat(:,1),temdat(:,2),temdat(:,4),x,y);
meshc(x,y,z);
axis([0,180,0,180]);

坐标放在D:\test.txt里(你也可以改成其他的),格式如下:
45 32 56
78 45 21
46 79 55
46 75 22
14 69 75
温馨提示:答案为网友推荐,仅供参考
第1个回答  推荐于2017-09-09
问题描述:这样的一个u.txt文件,用matlab从中读取数据,每次只读
取一行进行处理,然后继续...u.txt文件如下: 14 19 337 312 12
16 33 31 19 19 36 32 12 17 33 11 14 10 36 11 42 11 36 11
12 71 35 31 43 17 33 10 45 72 35 21
答案1:: 编写mymesh()函数:
function mymesh()
temdat=load('D:\test.txt');
if temdat== -1
('Error opening the file');endfigure;h=plot3(temdat(:,1),temdat(:,2),temdat(:,3));
set(h,'linestyle','none')hold on;grid on;[x,y]=meshgrid(linspace(-150,150,500),linspace(-
150,150,500));
z = griddata(temdat(:,1),temdat(:,2),temdat(:,4),x,y);
meshc(x,y,z);
axis([0,180,0,180]);
matlab读取txt文档数据
答案1:: 编写mymesh()函数:
function mymesh()
temdat=load('D:\test.txt');
if temdat== -1
('Error opening the file');endfigure;h=plot3(temdat(:,1),temdat(:,2),temdat(:,3));
set(h,'linestyle','none')hold on;grid on;[x,y]=meshgrid(linspace(-150,150,500),linspace(-
150,150,500));
第2个回答  2012-08-14
你说i的是什么意思啊
相似回答