Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

New to MATLAB?

Thread Subject:
Possible to store results as a matrix?

Subject: Possible to store results as a matrix?

From: Shaun Hurley

Date: 7 Jul, 2010 17:18:21

Message: 1 of 1

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!

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)


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
        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
        q = length(r)-1; % recalculate the number of elements in x
        p = p + 1;

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us