开发者

Matlab fopen command responds to string but not variable equaling same string

I'm wondering if anyone can shed some light on the following issue with Matlab fopen command:

>> [stat myjob] = unix('echo $PBS_NODEFILE'); % gets PBS file name with allocated nodes  
>> myjob

myjob =

/opt/torque/aux//66058.crunch.local


>> fid = fopen('/opt/torque/aux//66058.crunch.local')

fid =

     3

>> fgetl(fid)

ans =

compute-9-2

>> fclose(fid);

I need the names of the nodes I have to control some later decisions in the script. The above can work if I'm in an interactive PBS job, but for the most part though I need to launch these jobs without intervention. When I try to do this by the stored filename:

>> fid = fopen(myjob) % returns invalid                               

fid =

    -1

>> fgetl(fid)                                        
??? Error using ==> fgetl at 44
Invalid file开发者_C百科 identifier.  Use fopen to generate a valid file identifier.

Why, when I put in directly the value stored in myjob do I get a valid identifier, but when I put in myjob does it fail?

Thanks, Andrew


Try this:

fid = fopen(deblank(myjob));

Looking at the way your output is formatted above, there appears to be an extra empty line appearing after the value of myjob is displayed, which indicates there may be a newline character appearing at the end of the string. This newline will cause the file name to not be recognized, so you can remove any trailing whitespace like this from a string with the function DEBLANK (or you can remove trailing and leading whitespace with the function STRTRIM).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜