필터 지우기
필터 지우기

CELL2MAT does not support cell arrays containing cell arrays or objects

조회 수: 3 (최근 30일)
Reuben Addison
Reuben Addison 2023년 2월 11일
댓글: Walter Roberson 2023년 2월 13일
I am writing a function and it worked fine until I made a tweak it a pit then I got the above error
path1 = '/Users/punk/Documents/Data/PO3/';
path2 = '*.HWR';
direc = struct2table(dir([fullfile(path1,path2)]));
direc = sortrows(direc,'date');
table2struct(direc);
filenames = {direc.name};
for trialnumber = 1:length(filenames);
filename = filenames{trialnumber};
data = dlmread(fullfile(path1, num2str(cell2mat(filenames(trialnumber)))),'',1,0);
But I am getting this error
Error using cell2mat
CELL2MAT does not support cell arrays containing cell arrays or objects.
Error in Complete (line 38)
data = readtable(fullfile(path1, num2str(cell2mat(filenames(trialnumber)))),'',1,0);
  댓글 수: 3
Reuben Addison
Reuben Addison 2023년 2월 11일
The are all defined in my function, I will update that in my code above
Walter Roberson
Walter Roberson 2023년 2월 13일
You have mixed up the syntax of readtable() and dlmread() . When you use readtable(), unless the second parameter is an options object such as SpreadsheetImportOptions object, then everything after the first parameter must be name-value pairs. That might include 'NumHeaderLines' option -- but more likely considering you are using dlmread() is that your first row is headers, and you probably do not want to skip those when you readtable() as the header supplies the variable names.
Also, your filename is already a character vector; why are you using num2str() with it?

댓글을 달려면 로그인하십시오.

답변 (1개)

Jan
Jan 2023년 2월 11일
table2struct(direc);
This line converts the table direc to a struct, but ignores the result. In consequence this line has no effect.
Simplify your code by avoiding the useless conversion to table and back again:
path1 = '/Users/punk/Documents/Data/PO3/';
path2 = '*.HWR';
direc = dir(fullfile(path1, path2))); % No need for a concatenation with []
[~, idx] = sort([direc.datenum]);
direc = direc(index);
But what is "filenames" and "trialnumber"? Maybe you mean:
data = dlmread(fullfile(path1, direc(trialnumber).name), '', 1, 0);

카테고리

Help CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

태그

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by