필터 지우기
필터 지우기

Error "Function subindex is not defined for value of struct"

조회 수: 1 (최근 30일)
Bharath
Bharath 2015년 11월 5일
댓글: Bharath 2015년 11월 6일
Hi all,
I'm trying to read in multiple .txt files (each file around 400-900MB) which contain sensor channels channels data.I created a readIn function import_file which gives one output which is struct array of size 1X1 struct with 20 fields and value 1Xno.lines double. This array has all the variables from the data file.
function [Signals] = import_file(filename,startRow)
% Function to read in all channel information from each file.
delimiter = {'\t',' '};
formatSpec = '%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f';
fileID = fopen(filename,'r');
dataArray = textscan(fileID,formatSPec,'Delimiter','MultipleDelimsAsOne',true,'EmptyValue',NaN,'HeaderLines',startRow-1,'ReturnOnError',false);
EXPORT = [dataArray{1:end}];
%Defining Individual channels as struct array
Signals.Time = EXPORT(:,2);
.
.
.
.
Signals.n2 = EXPORT(:,21);
fclose(fileID);
clear file ID;
The rest of program is
myfiles = dir('*.txt');
for singlefile = myfiles' % forloop to read in each file
Signals(singlefile) = import_file(file.name,startRow);% storing each file information as a structure inside signal.
end
When I try to run this program I get an error
Function 'subsindex'is not defined for values of class 'struct'
Error in RD_Test_Run(line 69)
Signals(singlefile) = import_files(singlefile.name,startRow);
Could someone please enlighten where I'm going wrong. Thank you in advance.

채택된 답변

Matt J
Matt J 2015년 11월 5일
편집: Matt J 2015년 11월 5일
for i=1:length(myfiles)
singlefile = myfiles(i).name % forloop to read in each file
Signals{i}= import_file(singlefile,startRow);
end
  댓글 수: 3
Walter Roberson
Walter Roberson 2015년 11월 6일
Before the loop you can add
Signals = cell(length(myfiles),1);
but this is probably not going to make a tremendous difference. textscan() just takes time.
Beware that your code is not correct. You have
dataArray = textscan(fileID,formatSPec,'Delimiter','MultipleDelimsAsOne',true'EmptyValue',NaN,'HeaderLines',startRow-1,'ReturnOnError',false);
when you should have
dataArray = textscan(fileID, formatSPec, 'Delimiter', delimiter, 'MultipleDelimsAsOne', true, 'EmptyValue', NaN, 'HeaderLines', startRow-1, 'ReturnOnError',false);
Are you sure you want MultipleDelimsAsOne in conjunction with EmptyValue ?? That makes it difficult to figure out which column a particular value was intended for.
Bharath
Bharath 2015년 11월 6일
@Walter Roberson. Thanks for your answer. I'm sorry that was a typo. I edited it.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Text Files에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by