Looking for an efficient method to repeat the script command for multiple files
이전 댓글 표시
I seek a less time-consuming script function to repeat the process for multiple files in a folder. I have designed a script that can do this, but I believe there must be a more efficient method. Currently using:
for i=x1:x
name=sprintf('CSC%d.ncs',i);
initial='C:\Documents\MATLAB\Neuralynx\9Hz\';
test=strcat(initial,name);
[Timestamps{i}, Samples{i}, Header{i}]= Nlx2MatCSC(test, [1 0 0 0 1], 1, 1, []);
if i==1
save channel1 Timestamps* Samples* Header*
clear Header* Timestamps* Samples*
elseif i==2
save channel2 Timestamps* Samples* Header*
clear Header* Timestamps* Samples*
elseif i==3
save channel3 Timestamps* Samples* Header*
clear Header* Timestamps* Samples*
elseif i==4
save channel4 Timestamps* Samples* Header*
clear Header* Timestamps* Samples*
end
Useful suggestions greatly appreciated!!
댓글 수: 5
Adam
2018년 6월 27일
What exactly is it that you are trying to do?
Rosalind Heron
2018년 6월 27일
OCDER
2018년 6월 27일
And why must you save them as .mat files? Is the Nlx2MatCSC function slow, so you want to save the output as a .mat file to resume for later use? But then, you're already saving the outputs into a cell array and there's no need to load the .mat file later. Is the 3 output cell arrays preallocated before the loop?
Rosalind Heron
2018년 6월 27일
OCDER
2018년 6월 27일
Once you have the .mat files, how do you "restructure the data" from this .mat files? Can you show us that code too? Just trying to see if we can go from directly from load .ncs file to the joined data:
load ncs -> save mat -> load mat -> join data %your current strategy
load ncs -> join data %this would be nicer
답변 (3개)
dpb
2018년 6월 27일
folder='C:\Documents\MATLAB\Neuralynx\9Hz\'; % target subdirectory
file='CSC*.ncs'); % file suitable wildcard pattern
d=dir(fullfile(folder,file)); % get the dir() listing
for i=1:length(d) % process the files
[Timestamps{i}, Samples{i}, Header{i}]= Nlx2MatCSC(test, [1 0 0 0 1], 1, 1, []);
...
At this point need more detail on what the variables are and how they need to be processed.
In general, creating named sequential files/variables is NOT the way to proceed.
If, for example, the timestamps are the same and the data are simple values for each of the channels, it might make sense to build a timetable structure of them all.
Jan
2018년 6월 27일
It is a bold guess only:
initial='C:\Documents\MATLAB\Neuralynx\9Hz\';
for i = 1:x
name = sprintf('CSC%d.ncs',i);
test = fullfile(initial, name);
[Timestamps, Samples, Header]= Nlx2MatCSC(test, [1 0 0 0 1], 1, 1, []);
save(sprintf('channel%d', i), 'Timestamps', 'Samples', 'Header');
end
This will not be much faster, because the main work is spent in Nlx2MatCSC and in save.
Rosalind Heron
2018년 7월 5일
카테고리
도움말 센터 및 File Exchange에서 Workspace Variables and MAT Files에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!