Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8888551
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T22:04:32+00:00 2026-06-14T22:04:32+00:00

so I have a matrix Data in this format: Data = [Date Time Price]

  • 0

so I have a matrix Data in this format:
Data = [Date Time Price]

Now what I want to do is plot the Price against the Time, but my data is very large and has lines where there are multiple Prices for the same Date/Time, e.g. 1st, 2nd lines

29  733575.459548611  40.0500000000000
29  733575.459548611  40.0600000000000
29  733575.459548612  40.1200000000000
29  733575.45954862   40.0500000000000

I want to take an average of the prices with the same Date/Time and get rid of any extra lines. My goal is to do linear intrapolation on the values which is why I must have only one Time to one Price value.

How can I do this? I did this (this reduces the matrix so that it only takes the first line for the lines with repeated date/times) but I don’t know how to take the average

function [ C ] = test( DN )

[Qrows, cols] = size(DN);
C = DN(1,:);

for i = 1:(Qrows-1)
if DN(i,2) == DN(i+1,2)
    %n = 1;
    %while DN(i,2) == DN(i+n,2) && i+n<Qrows
    %        n = n + 1;
    %end
    % somehow take average;
else
    C = [C;DN(i+1,:)];
end
end
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T22:04:33+00:00Added an answer on June 14, 2026 at 10:04 pm

    [C,ia,ic] = unique(A,'rows') also returns index vectors ia and ic
    such that C = A(ia,:) and A = C(ic,:)

    If you use as input A only the columns you do not want to average over (here: date & time), ic with one value for every row where rows you want to combine have the same value.

    Getting from there to the means you want is for MATLAB beginners probably more intuitive with a for loop: Use logical indexing, e.g. DN(ic==n,3) you get a vector of all values you want to average (where n is the index of the date-time-row it belongs to). This you need to do for all different date-time-combinations.

    A more vector-oriented way would be to use accumarray, which leads to a solution of your problem in two lines:

    [DateAndTime,~,idx] = unique(DN(:,1:2),'rows');
    Price = accumarray(idx,DN(:,3),[],@mean);
    

    I’m not quite sure how you want the result to look like, but [DataAndTime Price] gives you the three-row format of the input again.

    Note that if your input contains something like:

    1 0.1 23
    1 0.2 47
    1 0.1 42
    1 0.1 23
    

    then the result of applying unique(...,'rows') to the input before the above lines will give a different result for 1 0.1 than using the above directly, as the latter would calculate the mean of 23, 23 and 42, while in the former case one 23 would be eliminates as duplicate before and the differing row with 42 would have a greater weight in the average.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a large sparse matrix stored in Compressed Row Storage (CRS) format. This
I have a matrix of objects that contains data in this form: name A,2,name
I have a matrix of data (the columns represent time, and the rows spectrum
I have a matrix A which I want to convert into a data.frame of
I currently have data that is in the following format (note, this is 1
I have to scan a Data Matrix written on something like this . The
I have this file, data.txt, the content is: 100X00 20X0X0 3000XX 4X00XX I want
I have a matrix (Data) which looks like this: (start) (stop) (strand) (gene number)
I have an matrix in this format that I am trying to validate and
I have a matrix of data, m : 12345 12348 2011-05-13 NA 0.18001079 2011-05-16

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.