fopen is returning ''

2 ビュー (過去 30 日間)
Mohan
Mohan 2011 年 11 月 22 日
Hello,
While I am trying to open a file using fopen the file id is returning ''.
I am attaching the error here, when using the whole file location it is working fine but when giving variables its not.
fopen(strcat(DirPath,'/',SbjList{1}(1,:),'/',SbjList{2}(1,:),'/FREESURFER/stats/aseg.stats'))
ans =
''
K>> strcat(DirPath,'/',SbjList{1}(1,:),'/',SbjList{2}(1,:),'/FREESURFER/stats/aseg.stats')
ans =
'/raid6/data9/CSP4REST/FS5.1_RES_5/5002/tp1/FREESURFER/stats/aseg.stats'
K>> fopen('/raid6/data9/CSP4REST/FS5.1_RES_5/5002/tp1/FREESURFER/stats/aseg.stats')
ans =
12

回答 (2 件)

Walter Roberson
Walter Roberson 2011 年 11 月 22 日
strcat() is returning a cell array that contains the string. You cannot fopen() a cell array.
I would suspect that DirPath is a cell array containing one string.
I suggest you use
[fid, message] = fopen(strcat(DirPath,'/',SbjList{1}(1,:),'/',SbjList{2}(1,:),'/FREESURFER/stats/aseg.stats'))
and look at the message generated.
If I am correct in my suspicion, changing to DirPath{1} should fix the problem.

Mohan
Mohan 2011 年 11 月 22 日
Hello Walter,
Thanks for the information but still when I debugging it, DirPath is just a variable having the path. When I give it in command window the following result popped up.
K>> DirPath
DirPath =
/raid6/data9/CSP4REST/FS5.1_RES_5.
and when I give DirPath{1} it showed an error
??? Cell contents reference from a non-cell array object.
and when I used [fid, message], both of them returning null ('').
  1 件のコメント
Walter Roberson
Walter Roberson 2011 年 11 月 22 日
In any case, the strcat() is returning a cell array. You can see that by examining your output and examining the output differences for the following two expressions:
'Hello'
{'Hello'}

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by