File Exchange

image thumbnail

MAX WIDTH

CALCULATING MAX WIDTH FROM A SERIES

1 Download

Updated

View License

HOW TO FIND IN A EASSY WAY THE MAXIM AND MINIM WIDTH IN A SIGNAL OSCILLATING FUNCTION

Comments and Ratings (4)

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.

Jan Simon

Jan Simon (view profile)

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.

John D'Errico

John D'Errico (view profile)

Note that:

- 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?

%clear all;
function widthA(d)

%how does it work?
%widthA(d)
%d=[2 2 4 3 6 4 3 2 7 9 5 7 18];
% where d is your data
N=length(d);

%i=1;
%SD1 = d(:,i:N-1)
%SD2 = d(:,i+1:N)
%d1=SD1-SD2

for i = 1
SD1 = d(:,i:N-1);
SD2 = d(:,i+1:N);
d1=(abs(SD1))-(abs(SD2));
%corr(SD1(:,i:N-1),SD2(:,i:N-1))
%plot(ds)
end
df = max(d1)
%ad = min(d1)

[r,c,v] = find(d1==df);
%d1n = find(min(d1))
fl1=d(1,c)
fl2=d(1,c+1)

Jan Simon

Jan Simon (view profile)

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.

Updates

1.2

IF YOU HAVE ANY SIGNAL OSCILLATION, YOU CAN FIND THE BIGGER AND SHORTER SIGNAL OR WIDTH

1.1

Calculate the bigger width of a sinus series

MATLAB Release
MATLAB 7.8 (R2009a)

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video