24小时热门版块排行榜    

CyRhmU.jpeg
查看: 1113  |  回复: 3

仇小仇

铁虫 (初入文坛)

[求助] matlab调试问题

用matlab将.car文件转换为lammps的data文件时总是报错
运行到:[~,x,y,z,~,element1,perx,pery,perz,charge] = read_msi_file(filename);
报错:??? [~,x,y,z,~,element1,perx,pery,perz,charge] = read_msi_file(filename);
      |
Error: Expression or statement is incorrect--possibly unbalanced (, {, or [.
read_msi_file源文件如下:function [ID,x,y,z,monomer,element,perx,pery,perz,charge] = read_msi_file(filename)

%filename = 'poly.car';
fid = fopen(filename);

% read the file header
header.line1 = fgetl(fid);
header.line2 = fgetl(fid);
header.line3 = fgetl(fid);
header.line4 = fgetl(fid);

% Get the periodic boundary lengths
tline = fgetl(fid);
text_format='%*s %f %f %f %*f %*f %*f %*s';
clear C
C = textscan(tline, text_format, 1);%第5行 C[1]~C[3]

perx = C{1};
pery = C{2};
perz = C{3};

% Output parameters into element for element 'ename'
tline = fgetl(fid);%第六行
continue_loop = 1;
count = 0;
while continue_loop

   text_format='%s %f %f %f %s %u %s %s %f';
   clear C
   C = textscan(tline, text_format, 1);%C[1]~C[9]
   count = count + 1;

   ID{count} = C{1};
   x(count) = C{2};%double
   y(count) = C{3};
   z(count) = C{4};
   monomer(count) = C{6};%单元结构unit32
   element{count} = C{8};
   charge(count) = C{9};
   
   tline = fgetl(fid);

   matches = strfind(tline, 'end');
   num = length(matches);
   if num > 0 && matches == 1
       tline = fgetl(fid);
       matches = strfind(tline, 'end');
       num = length(matches);
       if num > 0 && matches == 1
            continue_loop = 0;
       end
   end
end
fclose(fid);

end
read_msi_file源文件运行时没有问题,[~,x,y,z,~,element1,perx,pery,perz,charge] = read_msi_file(filename);这句话中的标点也都是英文符号下的 实在不知道错误在哪
请各位高手帮帮忙~~
回复此楼
学海无涯
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

csgt0

荣誉版主 (著名写手)

彩色挂图

【答案】应助回帖


感谢参与,应助指数 +1
chaizhm: 金币+1, 谢谢~ 2012-06-27 10:44:14
表面上看没有问题啊,可能你在调用前对x,y,z,element1,perx,pery,perz,charged定义的数据形式与函数返回形式不一样。最好把你的文件也传上来
showmethemoney
2楼2012-06-26 18:03:21
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

仇小仇

铁虫 (初入文坛)

引用回帖:
2楼: Originally posted by csgt0 at 2012-06-26 18:03:21
表面上看没有问题啊,可能你在调用前对x,y,z,element1,perx,pery,perz,charged定义的数据形式与函数返回形式不一样。最好把你的文件也传上来

源文件是一个.car文件 是由materials studio生成的 这个程序在我学姐的电脑里运行就没有问题 在我的电脑里运行就是有问题 我以为可能是matlab的问题 于是就卸载了又重装了一次 可还是报错
学海无涯
3楼2012-06-28 10:23:49
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

csgt0

荣誉版主 (著名写手)

彩色挂图

【答案】应助回帖

★ ★ ★ ★ ★
chaizhm: 金币+1, 谢谢~ 2012-06-28 13:56:35
仇小仇: 金币+4 2012-07-13 17:50:59
引用回帖:
3楼: Originally posted by 仇小仇 at 2012-06-28 10:23:49
源文件是一个.car文件 是由materials studio生成的 这个程序在我学姐的电脑里运行就没有问题 在我的电脑里运行就是有问题 我以为可能是matlab的问题 于是就卸载了又重装了一次 可还是报错...

可能跟版本有关系,而且你没有给出调用此函数之前的情况,
你可以把整个程序和文件传上来让别人看看。
showmethemoney
4楼2012-06-28 11:18:46
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
相关版块跳转 我要订阅楼主 仇小仇 的主题更新
信息提示
请填处理意见