Prev: s-function example
Next: MATLAB indexing issue
From: Shaun Hurley on 7 Jul 2010 13:18 Below is my program. I end up with 6 sets of data (a range and mean for each set). I have more work to do with these numbers so I am trying to put it into a matrix; is this possible? Thank you! clc clear all x= [80 20 60 -100 40 -20 0 -80 80 -40 60 0 80]; q=length(x)-1; % number of elements in x p=1; % starting with x(1) p=1; data=zeros(7,7); while p<=q % (or maybe p<=q) loop from p to q r(p)=abs(x(p)-x(p+1)); % calculate 1st range (to be compared w/ 2nd) r(p+1)=abs(x(p+1)-x(p+2)); % calculate 2nd range (to be compared w/ 1st) if r(p)<=r(p+1) % if 1st number is <= to 2nd range=r(p) mean=(x(p)+x(p+1))/2 % calculate the mean of numbers about to be deleted x(p) = []; % erase 1st x value x(p) = []; % erase 2nd x value x; % recalculate x after deleting x's r=[]; % clear r so the last for p=1:length(x)-1 r(p)=abs(x(p)-x(p+1)); % calculate r vector end r; q = length(r)-1; % recalculate the number of elements in x p=1; else x; p = p + 1; end end
|
Pages: 1 Prev: s-function example Next: MATLAB indexing issue |