mlh_2002 发表于 2008-10-19 17:11

我导入数据的问题,不知道怎么解决

使用matlab web server遇到的问题!
大家好,我是使用matlab web server时候,我需要分析,shiyan.dat这种类型的数据文件,但是不知道如何在html页面上做一个打开文件的按钮,因为数据文件要不断变化,我看到官方解决方式是下面的形式,但是我自己不会用,请大侠门帮助。Subject:Why can't I perform File I/O operations from my MATLAB Web Server M-file Application?
Problem Description:Why can't I perform File I/O operations from my MATLAB Web Server M-file Application?

I am developing a MATLAB Web Server application that is required to be able to load data from a file on the server. However, I am unable to get this to work.

My Web Server M-file includes the following code:

fid = fopen('dummy2.txt','rt');
i = 1;
s_data = fgetl(fid);

while(s_data ~= -1)
dnum = str2num(s_data);
disp(dnum)
if (i == 1)
data = dnum;
i = -1;
else
data = ;
end
s_data = fgetl(fid);
end

fclose(fid);

Solution:As a workaround, you can use Java I/O routines to read the data into MATLAB as illustrated here:

myfile = java.io.FileInputStream('dummy2.txt');
reader= java.io.InputStreamReader(myfile);
line = java.io.BufferedReader(reader);

i = 1;
s_data = readLine(line);
while(prod(size(s_data)) ~= 0)
dmat = str2mat(s_data);
dnum = str2num(dmat);
if (i == 1)
data = dnum;
i = -1;
else
data = ;
end
s_data = readLine(line);
end

For more information on calling Java from MATLAB, take a look at Chapter 7 of the "External Interfaces/API" documentation.

happy 发表于 2008-10-21 06:05

请说清楚什么地方不会?官方给出的实例不是挺清楚的吗?
页: [1]
查看完整版本: 我导入数据的问题,不知道怎么解决