声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

查看: 1196|回复: 1

[混合编程] 我导入数据的问题,不知道怎么解决

[复制链接]
发表于 2008-10-19 17:11 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?我要加入

x
使用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 = [data;dnum];
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 = [data;dnum];
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.
回复
分享到:

使用道具 举报

发表于 2008-10-21 06:05 | 显示全部楼层
请说清楚什么地方不会?官方给出的实例不是挺清楚的吗?
您需要登录后才可以回帖 登录 | 我要加入

本版积分规则

QQ|小黑屋|Archiver|手机版|联系我们|声振论坛

GMT+8, 2024-11-26 01:34 , Processed in 0.051359 second(s), 17 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表