From: Jan Simon on 18 Feb 2010 16:21 Dear Mike! > values = cell(50, 4); > for i = 1:numberOfColons > individualEvent = substr(compressedEvents, startOfEvent, (endi(i) - startOfEvent - 1)); > startOfEvent = endi(i); > boxAndNeuron = substr(individualEvent, 0, 1); > switch boxAndNeuron > case '*' % v-- Box 1 --v > box = 1; > neuron = 1; > case '+' > box = 1; > neuron = 2; > case '\' > box = 1; > neuron = 3; > case '-' > box = 1; > neuron = 4; > case '.' % v-- Box 2 --v > box = 2; > neuron = 1; > case '/' > box = 2; > neuron = 2; > case '0' > box = 2; > neuron = 3; > case '1' > box = 2; > neuron = 4; > case '2' % v-- Box 3 --v > box = 3; > neuron = 1; > case '3' > box = 3; > neuron = 2; > case '4' > box = 3; > neuron = 3; > case '5' > box = 3; > neuron = 4; > case '6' % v-- Box 4 --v > box = 4; > neuron = 1; > case '7' > box = 4; > neuron = 2; > case '8' > box = 4; > neuron = 3; > case '9' > box = 4; > neuron = 4; > end > > channel = ((substr(individualEvent, 1, 1))-0) - 64; > eventLength = length(individualEvent); > timeStampSubstring = substr(individualEvent, 2); > [endInteger] = regexp(timeStampSubstring,'[.]'); > integer = hex2dec(substr(timeStampSubstring, 0, (endInteger(1) - 1))); > fraction = hex2dec(substr(timeStampSubstring, endInteger(1), (eventLength - endInteger(1)))); > timestamp = integer + (fraction / 1000000); > values(i,:) = { box channel neuron timestamp }; > end > > decompressedArray = decompress(dataReceived); > dataArray = cat(1, dataArray, decompressedArray); > I need any empty rows at the end of the returned cell array to be removed before concatenating. I will look at teh current suggestions and see if they are what I need. ------------------------------- Hmm - the code is not easy to read. ??? If you assign exactly [numberOfColons] rows, why not just create this number of cells?! Then you do not have to crop them finally. values = cell(numberOfColons, 4); for i = 1:numberOfColons ... > values(i,:) = { box channel neuron timestamp }; I assume this to be faster - but please test this by your own: values{i,1} = box; values{i,2} = channel; values{i,3} = neuron; values{i,4} = timestamp; > channel = ((substr(individualEvent, 1, 1))-0) - 64; What is SUBSTR?! It would be nice to explain what you are posting. If "substr(individualEvent, 0, 1)" means "individualEvent(1)" I'd definitely recommend the later. However, it can be simplified to: channel = substr(individualEvent, 1, 1) - 64; The switch expression is large. I'd expect something like this to be more efficient: index = findstr(substr(individualEvent, 0, 1), '*+\-./0123456789'); box = ceil(index / 4); neuron = mod(index - 1, 4) + 1; > fraction = hex2dec(substr(timeStampSubstring, endInteger(1), (eventLength - endInteger(1)))); I expect sscanf(substr(timeStampSubstring, endInteger(1), (eventLength - endInteger(1))), '%x') to be faster. Kind regards, Jan
From: Mike on 19 Feb 2010 12:01 It's often the simplest solution that gets overlooked. It never occurred to me that I know how many events I would have in my data based on the number of colons I found! I guess sometimes it takes a fresh pair of eyes. Thank you for looking through my code and noticing that. Regards, Mike
First
|
Prev
|
Pages: 1 2 Prev: modem.oqpsk with half sine wave (IEEE 802.15.4) Next: Matlab object blocks |