Thread Subject: Extracting data

Subject: Extracting data

From: yingmu huadao

Date: 30 Dec, 2008 06:08:01

Message: 1 of 3

Hi all,

I have a variable, a = <1 x 102300 double>. How do I go about extracting data from every 4 numbers and store the data in another variable, for eg, the 1,5,9,13 (position) data, store in variable b.
Thanks in advance.

Yingmu

Subject: Extracting data

From: gcet03

Date: 30 Dec, 2008 07:29:08

Message: 2 of 3

clear all;
b=ones(1,length(a)/4);
c=0;
for i=1:length(a)
    if rem(i,4)==0
        c=c+1;
        b(c)=a(i);
    end
end

Run above code with your values in stored in a variable

Subject: Extracting data

From: Bruno Luong

Date: 30 Dec, 2008 08:03:03

Message: 3 of 3

"yingmu huadao" <yingmusg@yahoo.com.sg> wrote in message <gjcds1$8j7$1@fred.mathworks.com>...
> Hi all,
>
> I have a variable, a = <1 x 102300 double>. How do I go about extracting data from every 4 numbers and store the data in another variable, for eg, the 1,5,9,13 (position) data, store in variable b.
> Thanks in advance.
>
> Yingmu

b=a(1:4:end)

Bruno

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

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.

rssFeed for this Thread

Contact us at files@mathworks.com