Code covered by the BSD License  

Highlights from
datashift

4.0

4.0 | 1 rating Rate this file 0 Downloads (last 30 days) File Size: 2.33 KB File ID: #19975

datashift

by Ali Mohammad Razeghi

 

19 May 2008 (Updated 20 May 2008)

Finds the maximum difference between numbers of a set then shifts the numbers up and down.

| Watch this File

File Information
Description

Finds the difference between two near elements in a set of numbers then finds the maximum of the differences then separates the set into two parts and shift them close to each other. The "a" parameter says to code how much must the lower subset shifts up and the higher subset shifts down.

Clarification: The reason of writing this code is a laboratory
experiment. In the experiment we have a change of two lamps. This change
constructs a gap in the set of experiments data that we know that it must be not realy exist for a substance of experiment and the lamp changing cause that not the substance. This program finds the gap in the set of numbers then shifts two subsets close to each other.

Example: A = [ -3 -1 1 2 3 7 8 10 11 13 15 ] ; B = datashift ( A , 1 )
B = -2 0 2 3 4 4 5 7 8 10 12

MATLAB release MATLAB 7.2 (R2006a)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (1)
20 May 2008 John D'Errico

This is a pretty specific tool, solving a specific problem. But it does what it says it does. It has got nice error checking, and fairly complete help, plus an example. Mlint found nothing to complain about.

The H1 line, i.e., the first comment line, was too short. In fact, the first sentence in the comments does perform the job of an H1 line, but it is spread over three comment lines in the help. Since lookfor only looks at that very FIRST line, I might have suggested an H1 line something like this:

% datashift: repairs a broken sequence of numbers, shifting the two pieces together

This is a short enough line that it will fit into a single comment line, but it is also descriptive as an H1 line.

One other point on the help. In my testing, I tried some sequences with several breaks in the sequence. datashift appears to look for the single largest break, repairing that by shifting the subsequences together. It will not find subsequences separated by several breaks of different sizes. This might have been more clearly explained in the help.

The code itself is not fully vectorized, not in itself a true flaw. But it could be simplified by the use of artful vectorization. For example, rather than the loop:

% Checks for complex numbers
for i = 1 : L
    
    if imag ( A ( i ) ) ~=0
        error 'A complex number(s) in the set has found.'
    end % End of if loop.
    
end % End of for loop.

The author could as easily have done something like
if any(imag(A)) ~= 0

Or perhaps even simpler, just use a test like

is ~isreal(A)
   error 'A complex number(s) in the set was found.'
end

Again, this was not really a flaw, more an issue of programming style. There are a few points where I did see nicely appropriate vectorizations used.

I do like the commenting style used by the author. Having many comments costs you nothing, so use them freely! You will appreciate them next year when you need to modify your code, or fix some bug that turns up. Well done here.

The issues I've pointed out are not really that serious ones, they did not bias my rating significantly downwards. I'll happily return and raise my rating to a 5 with a repaired H1 line, plus a comment in the help that says what happens when no single largest difference is identified.

I'll offer my commendations to the author for continuously improving his Matlab skills, as well as his codes on the FEX.

Please login to add a comment or rating.
Tag Activity for this File
Tag Applied By Date/Time
data Ali Mohammad Razeghi 22 Oct 2008 10:02:11
shift Ali Mohammad Razeghi 22 Oct 2008 10:02:11
difference Ali Mohammad Razeghi 22 Oct 2008 10:02:11
elements Ali Mohammad Razeghi 22 Oct 2008 10:02:11
maximum Ali Mohammad Razeghi 22 Oct 2008 10:02:11

Contact us at files@mathworks.com