Loading .txt that are in a cell array

Dear Matlab users,
I'm currently facing a problem when I'm loading my data for research (used 2 sample subjects -> Proefpersoon*). When i'm loading my data into matlab it goes into a cell that looks like this:
Within these text files is data gathered from a Force plate. But I unable to get/load the data from the cell. For example, i want to filter some of the data from pp1 and pp2.... How do I acces that data trough the cell?
Hope someone can help me! :)

답변 (2개)

dpb
dpb 2014년 4월 29일

0 개 추천

You've loaded a file that seemingly contains a list of files, not the actual data.
You need to either iterate thru that list of files and open them to extract the data or, my general favorite route is to use dir to simply create the list of files of interest in a directory structure and then iterate over that to open the files...

댓글 수: 1

Jeroen
Jeroen 2014년 4월 29일
편집: Jeroen 2014년 4월 29일
I understand what you're saying, but i'm not really sure what to do in Matlab to solve this!?
I've used this code to load the data:
function fileList = DataLaden(dirName)
dirData = dir(dirName);
dirIndex = [dirData.isdir];
fileList = {dirData(~dirIndex).name}';
if ~isempty(fileList)
fileList = cellfun(@(x)fullfile(dirName,x),fileList, 'UniformOutput',false);
end
subDirs = {dirData(dirIndex).name};
validIndex = ~ismember(subDirs,{'.','..'});
for iDir = find(validIndex)
nextDir = fullfile(dirName,subDirs{iDir});
fileList = [fileList; DataLaden(nextDir)];
end
end

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

dpb
dpb 2014년 4월 29일

0 개 추천

I'd more go like...
wd='D:\Desktop\BOP Metingen\Proefpersoon2'; % the directory location
d=dir(fullfile(wd,'*.txt'); % return the files there
for i=1:length(d)
% insert code to read the file here...which, exactly, function is most simple to use depends on the form of the data therein that's not been given
...
end
Rather than hardcoding that working directory if it changes would be to use the file that contains the list as input and read it from it...it's still as simple or more so to use dir to retrieve the files to process tho, imo...it just automates the directory selection.
And, of course, you can insert whatever logic needed to parse the filenames to do what needs to be done with each depending on the content of each and what want to do with them. Another "trick" since you apparently have the two sets to compare would be to differentiate in the dir call--
I'd go like...
wd='D:\Desktop\BOP Metingen\Proefpersoon2'; % the directory location
d=dir(fullfile(wd,'*.txt'); % return the files there
for i=1:length(d)
% insert code to read the file here...which, exactly, function is most simple to use depends on the form of the data therein that's not been given. I'll sample a *fopen*
fid=fopen(d(i).name,'r');
...
% when done reading, close the file..
fid=fclose(fid);
...
end
And, of course, you can insert whatever logic needed to parse the filenames to do what needs to be done with each depending on the content of each and what want to do with them. Another "trick" since you apparently have the two sets to compare would be to differentiate in the dir call--
d1=dir(fullfile(wd,'pp1*.txt'); % return the '1' set of files
d2=dir(fullfile(wd,'pp2*.txt'); % and the 2nd...
for i=1:length(d1) % both have same number
fid1=fopen(d1(i).name,'r'); % open, read each of comarative ones
fid2=fopen(d2(i).name,'r');
...
Could sort the two directories to ensure they're returned in the same order, etc., ...

카테고리

도움말 센터File Exchange에서 Search Path에 대해 자세히 알아보기

질문:

2014년 4월 29일

답변:

dpb
2014년 4월 29일

Community Treasure Hunt

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

Start Hunting!

Translated by