Well, somebody asked me this code, I just tried to design a good one, I find it very helpful maybe not for you. On the other hand some code likes correlation is not well clear and this is why I create my own codes. Thanks for comment I will consedire them. This is applied for Signals, if you never used signals you can try.
Now you have added a help text. Unfortunately this does not explain clearly, what the function calculates. At least I do not understand what "CALCULATE THE WIDTH ONE BY ONE AND CATCH THE BIGGER ONE" means.
The code seems like you want to calculate the minimal and maximal differences between neighboring elements. This can be done faster and simpler by:
dist = abs(diff(d));
[minValue, minIndex] = min(dist);
[maxValue, maxIndex] = max(dist);
The function is still not usable. Of course learning to use Matlab is done step by step only. But I do not see a reason to share such codes with others.
- Fully half the code is commented out.
- It starts with a clear all, that is commented out, but is unnecessary in a function.
- There is NO documentation, except for the trivial line: "How does it work", which does not actually tell how it works!!!!!
- The line "for i = 1" effectively executes "i = 1", but takes more programming effort, and confuses things. Why add an end statement when none is needed?
%how does it work?
%d=[2 2 4 3 6 4 3 2 7 9 5 7 18];
% where d is your data
There is not useful explanation what this function should achieve. The code is hard to read also, e.g. lines like "for i = 1" are confusing only. The fact, that this function has no outputs shows, that this is neither useful nor usable.
Please cleanup this function substantially and add a help text - see other submissions for examples.
03 Apr 2013
Calculate the bigger width of a sinus series
03 Apr 2013
IF YOU HAVE ANY SIGNAL OSCILLATION, YOU CAN FIND THE BIGGER AND SHORTER SIGNAL OR WIDTH