2013-10-29 66 views
1

當我運行下面的代碼,我得到了以下錯誤引用:錯誤:單元格內容從非單元陣列對象

Cell contents reference from a non-cell array object. 

folder可能需要1或多個文件夾

for x=1:numel(folder) 
    y{x} = fullfile(folder{x},'Status.xml'); 
    getFile = fileread(char(y{x})); 
    content{x} = strtok(getFile ,';'); 
end 


>>whos folder 
    Name  Size   Bytes Class  Attributes 

    folder  1x1    941 struct   


>> numel(folder) 
ans= 
1 
+0

也許在循環前初始化'y'爲'y = {}'? – Dan

+0

當你運行你的代碼 – Shai

+0

類型'>>哪個文件夾和'>>類(文件夾)'並且看到你得到的輸出時,它似乎沒有定義'文件夾'。 – Shai

回答

0

假設我認爲這應該工作:

y = cell(numel(folder), 1); 

for x=1:numel(folder) 
    y{x} = fullfile(folder{x},'Status'); 
    getFile = fileread(char(y{x})); 
    content{x} = strtok(getFile ,';'); 
end 

您的錯誤很可能與y{ii}。我猜y沒有預先定義。

另外:在y中使用ii作爲索引,而在循環中使用x

如果folder是一個正常的矩陣,您是否嘗試過使用folder(x)

UPDATE:

我從你的更新問題,看到folderstruct,而不是細胞。嘗試以下方法,您可以用.field替換您在folder中輸入的任何名稱。

y = cell(numel(folder), 1); 
content = cell(numel(folder), 1); 

for x=1:numel(folder) 
    y{x} = fullfile(folder(x).field,'Status'); 
    getFile = fileread(char(y{x})); 
    content{x} = strtok(getFile ,';'); 
end 
+0

當我執行y {x} = fullfile(文件夾{x},'Status')時,我得到了同樣的錯誤; – lola

+0

getFile = fileread(char(y {x}));不正確,因爲y {x} = fullfile(文件夾(x).field,'Status.xml');給出C \ Status.xml,而期望的文件是Controller \ Status.xml – lola

+0

我已更新如下:y {x} = fullfile(folder.field(x),'Status.xml') – lola