Hi all, I need to write a program for reading csv files, produced while recording trajectories of reflective markers (points) with a 3D camera. The first 44 lines of the csv file do not contain important data of the tracked markers. All the next lines contain comma separated data taken with a frequency of 120 Hz. So the 45th line is taken at time 0 and so on. These lines include x,y and z coordinates of all the tracked markers at this time. It is not necessary that the same markers were tracked in all the lines, therefore markers with new id numbers appear (Marker-idNumber).
I would like to store the x,y,z data for each marker in a cell array with marker names, which contain the marker's coordinates through time. For beginning we could assume that same markers appear in each line!- I guess this is a much easier task and I have almost done it (look ahead).
I found an existing program, which performs a similar job. I adapted the program for my needs, but due to my lack of programming knowledge I failed to succeed. If anyone knows what I am doing wrong I would appreciate your help.
Here is my code up to now (example data file attached):
clear allopenedFile = fopen('ReducedData.csv','r');currentLineNo = 0;%we go through the first lines which dont contain data of interest
for lineIndex = 1:43 lineContent = fgetl(openedFile); currentLineNo = currentLineNo +1;endcommaSeperatedValues = regexp(lineContent, ',', 'split');numberOfFrames = str2num(commaSeperatedValues{3});%We go to frame 0
for lineIndex = 44 : 45 lineContent = fgetl(openedFile); currentLineNo = currentLineNo + 1;endframeIndex = 0;for lineIndex = 1:numberOfFrames currentLineNo = currentLineNo + 1; frameIndex = frameIndex+1; frameLine = fgetl(openedFile); commaSeperatedValues = regexp(frameLine, ',', 'split'); frameIndexFromFile = str2num(commaSeperatedValues{2}); timestamp = str2num(commaSeperatedValues{3}); numberOFTrackedMarkersInThisFrame = str2num(commaSeperatedValues{5}); % Get marker coordinates
idx = find(~cellfun(@isempty, strfind(commaSeperatedValues,'Marker-'))); %searches for locations of word 'Marker'
for c2 = 1 : length(idx) coor = cellfun(@str2double, commaSeperatedValues(idx(c2)-4:idx(c2)-2)); %reads the coordinates of each Marker
nums = regexp(commaSeperatedValues{idx(c2)},'\d*','match'); %reads the identification numbers of markers
MarkerCoordinates(str2double(nums{c2})).(sprintf('Marker%s',nums{c2}))(frameIndex,:) = coor; %stores data into a CellArray??
end end
The exemplar data contains rows of different markers. But we can check if the code works for lines with same markers in all lines by changing the perturbation field of the second last for loop ( "for lineIndex = 1:numberOfFrames" – instead of numberOfFrames = 1). When I do this I get error: "Index exceeds matrix dimensions." So how can I make the program work for lines with same markers in each line, and how could I upgrade the program to work for various markers in lines? Thank you.
Regards,
Jurij Hladnik
Best Answer