From: Shaun Hurley on
"Matt Fig" <spamanon(a)yahoo.com> wrote in message <i12cdr$3s7$1(a)fred.mathworks.com>...
> This would seem to do it as a first step. The data re-writing will kill you with very long vectors. I leave the commenting to you.
>
> % Data
> x = [80 20 60 -100 40 -20 80]
>
>
>
> % Engine
> cnt = 0;
> F = cell(floor(length(x)/2),1);
>
> while length(x)>1
> idx = find(diff(abs(diff(x)))>=0,1,'first');
> if isempty(idx)
> break
> end
> cnt = cnt + 1;
> F{cnt} = x(idx:idx+1);
> x(idx:idx+1) = [];
> end
>
> F = F(1:cnt);
> mn = cellfun(@mean,F)
> rng = cellfun(@(x) abs(diff(x)),F)

That's amazing how you did that so fast. I have been working on this for over a week now. (I'm new to this) I really appreciate this. I just posted another message. I was able to pull out the ranges and means, but not as vectors. Do you know how to do that? I would like to stick with what I've done because I understand it. If I need to though, I will try and go through and understand your way. Thank you again so much!
From: Matt Fig on
You should be able to store your data in an array. Here is your code modified somewhat for efficiency and with the data stored in array H. H should have all the data you need to do whatever you need afterward.


p = 1;
q = length(x)-2; % number of elements in x
H = zeros(2,floor(length(x)/2)); % Store information here.
cnt = 0;

while p<=q % (or maybe p<=q) loop from p to q
r(1) = abs(x(p)-x(p+1)); % calculate 1st range (to be compared w/ 2nd)
r(2) = abs(x(p+1)-x(p+2)); % calculate 2nd range (to be compared w/ 1st)
if r(1)<=r(2) % if 1st number is <= to 2nd
cnt = cnt + 1;
H(:,cnt) = x(p:p+1);
x(p) = []; % erase 1st x value
x(p) = []; % erase 2nd x value
q = q-2; % recalculate the number of elements in x
p = 1;
else
p = p + 1;
end
end

H = H(:,1:cnt);
mn2 = mean(H); % The means.
rng2 = abs(diff(H)); % The ranges.
From: Shaun Hurley on
Thank you so much!! I was able to finish my entire program today! At the rate I was going it was literally going to take at least a month. Everything works perfect, thank you again!
First  |  Prev  | 
Pages: 1 2
Prev: Wind barb plots
Next: Vector Field