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

  • Home
  • SEARCH
  • 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 6986107
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:45:59+00:00 2026-05-27T18:45:59+00:00

I need some help in this problem I have this matrix in MATLAB: A

  • 0

I need some help in this problem

I have this matrix in MATLAB:

A = [ 25    1.2    1
      28    1.2    2
      17    2.6    1
      18    2.6    2
      23    1.2    1
      29    1.2    2
      19    15     1
      22    15     2
      24    2.6    1
      26    2.6    2];  

1st column is some measured values for temperature

2nd column is an index code representing the color (1.2:red,…..etc)

3rd column is the hour of taking the sample. Only at hours from 1 to 2

I want the matrix to be controlled by 2nd column as follows:

if it is 1.2, the program will find the average of all temperatures at hour 1 that

corresponds to 1.2

So, here ( 25 + 23 )/2 = 24

and also finds the average of all temperatures at hour 2 and that corresponds

to 1.2, ( 28 + 29 ) /2 = 28.5

and this average values:

                     [24 
                      28.5]

will replace all temperature values at hours 1 and 2

that corresponds to 1.2 .

Then, it does the same thing for indices 2.6 and 15

So, the desired output will be:

B = [  24
       28.5

       15.5
       22

       24
       28.5

       19
       22

       15.5
       22]

My problem is in using the loop. I could do it for only one index at one run.

for example,

T=[];
   index=1.2;

   for i=1:length(A)
       if A(i,2)==index
        T=[T A(i,1)];
    else
        T=[T 0];
       end
   end

So, T is the extracted T that corresponds to 1.2 and other entries are zeros

Then, I wrote long code to find the average and at the end I could find the matrix

that corresponds to ONLY the index 1.2 :

B =   [24
       28.5

       0
       0

       24
       28.5

       0
       0

       0
       0]

But this is only for one index and it assigns zeros for the other indices. I can do this for all

indices in separate runs and then add the B’s but this will take very long time since my real

matrix is 8760 by 5 .

I am sure that there is a shorter way to do that.

Thanks

Regards

  • 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-05-27T18:46:00+00:00Added an answer on May 27, 2026 at 6:46 pm

    Try this:

    B = zeros(size(A, 1), 1);
    C = unique(A(:, 2))';
    T = [1 2];
    
    for c = C,
      for t = T,
          I1 = find((A(:, 2) == c) & (A(:, 3) == t));
          B(I1) = mean(A(I1, 1));
      end
    end
    

    Edit
    I think your expected answer is wrong for c = 2.6 and t = 1… Shouldn’t it be (17 + 24)/2 = 20.5?

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

Sidebar

Related Questions

I need some help in solving this problem. We have a large amount of
ASP.NET 4.0 Need some help with this vexing HTTP POST problem - I have
I need some help on this problem. It is about ASP.NET MVC3. I have
I have this strange problem I need some help with. This menu code goes
I need some help! I have no doubt this is a dumb problem that
Need some help with this problem in implementing with XSLT, I had already implemented
Well i need some help here i don't know how to solve this problem.
I really need some help with this as I have been trying to fix
Need some help to solve this. I have a gridview and inside the gridview
I need some help with this one.... I have this simple model: public class

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.