Results 1 to 5 of 5

Math Help - Matlab

  1. #1
    Newbie
    Joined
    Nov 2007
    Posts
    4

    Matlab

    hi, i would like to ask how can i do with MATLAB to find the sum values from a unique data.

    for example i have the data,

    p=[1 1 3 1 2 1 1 1 4 1 1 0.92]
    r=[0.1 0.2 0.3 0.3 0.3 0.5 0.6 0.7 0.8 0.8 0.9 0.91]

    as we can see there are three 0.3 in set r, and i would like to get the sum value of P ((3+1+2)) where r= 0.3, and the sum value of p ((4+1)) where r=0.8. while for the other P values with the distinctive r value will remain the same.

    thanks.
    Follow Math Help Forum on Facebook and Google+

  2. #2
    Junior Member qspeechc's Avatar
    Joined
    Oct 2007
    Posts
    73
    I am sorry, I am not quite sure I understand- what exactly are youtrying to do?
    Are we talking about P or p? What is P? MATLAB distinguishes between lower and upper case, ie. P is NOT the same thing as p. What has p to do with r? Are you trying to sum all the elements of the vector? Or count how many times a specific number occurs?
    Follow Math Help Forum on Facebook and Google+

  3. #3
    Newbie
    Joined
    Nov 2007
    Posts
    4
    sorry for the confusion. Actually all are lower case p.

    p r (in file PR.mat)
    1 0.1
    1 0.2
    1 0.3
    1 0.3
    1 0.4
    1 0.5
    1 0.6
    1 0.7
    1 0.8
    1 0.8
    1 0.9
    0.92 0.9
    0.92 0.91


    How do i isolate out the above data so that r will only have
    0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 0.91 and if the data for
    r repeat (for example 0.3, 0.8, 0.9) then i will
    have to get the sum of its p data.

    for example, i would like to have this result


    p r
    1 0.1
    1 0.2
    2 0.3
    1 0.4
    1 0.5
    1 0.6
    1 0.7
    2 0.8
    1.92 0.9
    0.92 0.91


    this is what i tried,


    load PR


    r;
    uR=unique(r); %%this is to get the unique num of set r (0.1,0.2,0.3,0.5,0.6,0.7,0.8,0.9,0.91)

    for i=1:8

    for loop =1:12

    pp(loop)=p(loop);
    psum=sum(pp)

    end

    end

    end

    but the pp i got is not according to the r. am i using the wrong way? what shall i proceed with?
    thanks.
    Follow Math Help Forum on Facebook and Google+

  4. #4
    Newbie
    Joined
    Nov 2007
    Posts
    4
    i've gt it. thanks for replying qspeechc.
    Follow Math Help Forum on Facebook and Google+

  5. #5
    Junior Member qspeechc's Avatar
    Joined
    Oct 2007
    Posts
    73
    Lol, I didn't do anything, but I'll take the thanks anyway
    Follow Math Help Forum on Facebook and Google+

Similar Math Help Forum Discussions

  1. Matlab help
    Posted in the Math Software Forum
    Replies: 1
    Last Post: February 11th 2010, 02:59 AM
  2. Matlab FFT Help
    Posted in the Math Software Forum
    Replies: 0
    Last Post: June 3rd 2009, 12:48 PM
  3. help about ODE in matlab
    Posted in the Math Software Forum
    Replies: 1
    Last Post: May 31st 2009, 03:10 AM
  4. Matlab Please help me
    Posted in the Math Software Forum
    Replies: 8
    Last Post: November 10th 2008, 04:40 PM
  5. Matlab
    Posted in the Calculus Forum
    Replies: 3
    Last Post: August 20th 2008, 10:39 PM

Search Tags


/mathhelpforum @mathhelpforum