Segment raw time series into chunks - matlab

I have written code in Matlab to read data from CSV file and store it in an array the file contain many rows and 4 main columns (time, x,y,z). the time is then divided into segments of 10 seconds. i have calculated the start and finish time for each segment, now I want to get the x,y,and z-data into each segment. can you guys help me please?

Related

EEGLAB: analysis of an specific section of an EDF file

I need to analize just one minute of a EEG test which last around 50 minutes. The part to be analized is around the minute 10, but I can't access only to that part, because EEGLAB loads always from the begining of the test by default.
When loading the EDF file, EEGLAB has the option: Data range (in seconds) to read (default all [num num]). I have tried here to insert only the time range needed, but I always get the begining of the test.

Need to extract earliest and latest data reads from each day with multiple time stamps (seconds)

I have a very large csv file which contains multiple meter reads for 8 meters - the readings have been taken every few seconds. I want to create a summary showing the first and last meter read for each day and for each meter - how could I do that please?

Performance issue with reading DICOM data into cell array

I need to read 4000 or more DICOM files. I have written the following code to read the files and store the data into a cell array so I can process them later. A single DICOM file contains 128 * 931 data. But once I execute the code it took more than 55 minutes to complete the iteration. Can someone point out to me the performance issue of the following code?
% read the file information form the disk to memory
readFile=dir('d:\images','*.dcm');
for i=1:4000
% Read the information form the dicom files in to arrays
data{i}=dicomread(readFile(i).name);
info{i}=dicominfo(readFile(i).name);
data_double{i}=double(data{1,i}); % convert 16 bit data into double
first_chip{i}=data_double{1,i}(1:129,1:129); % extracting first chip data into an array
end
You are reading 128*931*4000 pixels into memory (assuming 16-bit values, that's nearly 1 GB), converting that to doubles (4 GB) and extracting a region (129*129*4000*8 = 0.5 GB). You are keeping all three of these copies, which is a terrible amount of data! Try not keeping all that data around:
readFile = dir('d:\images','*.dcm');
first_chip = cell(size(readFile));
info = cell(size(readFile));
for ii = 1:numel(readFile)
info{ii} = dicominfo(readFile(ii).name);
data = dicomread(info{ii});
data = (1:129,1:129); % extracting first chip data
first_chip{ii} = double(data); % convert 16 bit data into double
end
Here, I have pre-allocated the first_chip and info arrays. If you don't do this, the arrays will be re-allocated every time you add an element, causing expensive copies. I have also extracted the ROI first, then converted to double, as suggested by Rahul in his answer. Finally, I am re-using the DICOM info structure to read the file. I don't know if this makes a big difference in speed, but it saves the dicomread function some effort.
But note that this process will still take a considerable amount of time. Reading DICOM files is complex, and takes time. I suggest you read them all in once, then save the first_chip and info cell arrays into a MAT-file, which will be a lot faster to read in at a later time.
You can run the profiler to check which part of the code is taking up most of the time! But as far as it looks to me is that its your iteration size & the time taken is very much genuine. You could try and use parallel computing ( parfor loop) if you have a multicore processor, that should decrease the runtime significantly depending upon the number of cores that you have.
One suggestion would be to exctract the 'first chip data' first and then convert it to double, as the conversion process takes a significant amount of time.

MATLAB: calculate with first row n times before moving to the next number

I am pretty new to Matlab and I could use some help. I have about 50k rows of data. What I would like to do is, that it would take the first number of the data, divide it by 12 and repeat the result 12 times then it would move on to the second number and do the same and so on and on till the end.
Best regards

How to control the duration of a VideoWriter function in MatLab? [duplicate]

This question already exists:
how to control the duration of a videoreader function in MatLab? [duplicate]
Closed 8 years ago.
I am using a Matlab code to record a video file using the VideoWriter function. I want to change the code to record only a certain part of the video file rather than the whole video. What command can I use to record only the first 40 secs of the data recorded at normal speed? I also want to know if there is a way I can record only a small part from the middle of the data recorded.
You can add conditional statements such as if to control the writing of the video file.
Alternatively, you can wrap the video writer function into a wrapper, which accepts your actual data, and a control boolean.
If you mean you want to record 40 seconds for each data set, with different frame rates, a wrapper function that takes frame rate and time length, and calculates the frame counts for itself may work.
If you mean you are frequently changing data sets, which will add up to one piece of video, and you want it be 40 second long, then a 'global' variable storing how many seconds you have recorded, as well as a function to calculate time increments, is needed.
Edited -
Based on your refined details, you may find these necessary and - hopefully - helpful.
exact frame rate for each data set.
a variable (should be in your controlling function/script) to store
how many milliseconds you already have.
a wrapper function that does the following job (and takes arguments
accordingly):
check if the current time already exceeds 40,000 milliseconds (if so, do nothing and return);
calculate the time period in milliseconds of your data to be added = (num of frames to record) / (frame rate per second) * 1000;
call video writer to record your data set, either frame by frame, or together in a whole;
add the time period into current time.
You can make it fancier by making it able to cut a piece of data series somewhere in the middle, so for example a 10-second data won't add the extra 4 seconds, if you already have 34 seconds on file.