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 897755
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T14:55:57+00:00 2026-05-15T14:55:57+00:00

I need to calculate the mean, standard deviation, and other values for a number

  • 0

I need to calculate the mean, standard deviation, and other values for a number of variables and I was wondering how to use a loop to my advantage. I have 5 electrodes of data. So to calculate the mean of each I do this:

mean_ch1 = mean(ch1);  
mean_ch2 = mean(ch2);  
mean_ch3 = mean(ch3);  
mean_ch4 = mean(ch4);  
mean_ch5 = mean(ch5);  

What I want is to be able to condense that code into a line or so. The code I tried does not work:

for i = 1:5  
  mean_ch(i) = mean(ch(i));  
end

I know this code is wrong but it conveys the idea of what I’m trying to accomplish. I want to end up with 5 separate variables that are named by the loop or a cell array with all 5 variables within it allowing for easy recall. I know there must be a way to write this code I’m just not sure how to accomplish it.

  • 1 1 Answer
  • 2 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-15T14:55:58+00:00Added an answer on May 15, 2026 at 2:55 pm

    You have a few options for how you can do this:

    • You can put all your channel data into one large matrix first, then compute the mean of the rows or columns using the function MEAN. For example, if each chX variable is an N-by-1 array, you can do the following:

      chArray = [ch1 ch2 ch3 ch4 ch5];  %# Make an N-by-5 matrix
      meanArray = mean(chArray);        %# Take the mean of each column
      
    • You can put all your channel data into a cell array first, then compute the mean of each cell using the function CELLFUN:

      meanArray = cellfun(@mean,{ch1,ch2,ch3,ch4,ch5});
      

      This would work even if each chX array is a different length from one another.

    • You can use EVAL to generate the separate variables for each channel mean:

      for iChannel = 1:5
        varName = ['ch' int2str(iChannel)];  %# Create the name string
        eval(['mean_' varName ' = mean(' varName ');']);
      end
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a set a data that I need to calculate their consecutive mean
Here's what I have: Standard Deviation Mean See code double[] series = { 150,
I need to calculate the number of FULL month in SQL, i.e. 2009-04-16 to
I need to calculate an end date based on todays date and a number
I need to calculate the number of decimal places for a float value, e.g.
I need to calculate the mean-squared error of a 16-bit operation for an arbitrary
I have a data.frame in panel format (country-year) and I need to calculate the
I need to calculate the number of weeks difference between the chosen date and
I need to calculate the distance (in meters and miles) between two coordinates given
I need to calculate date (year, month, day) which is (for example) 18 working

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.