COMPGROUPS.NET | Search | Post Question | Groups | Stream | About | Register

Average of matrix

• Email
• Follow

```Hi all,

My problem may be simple but I am new Matlab user and I found myself unable to find a solution so I ask for some help:

I have an one-column vector A<100x1>. I want to calculate the average of the rows in 10-tuples.

So i want to end up with 10 numbers where the first will be the average of the first 10 rows of A (1-10), the second the average of the next 10 rows (11-20) etc-etc.

How can I do that?
```
 0

See related articles to this posting

```mean(reshape(A,10,10))
```
 0

```Try reshape, i.e.

B = reshape(A,10,10);

then take the mean of each column

M = mean(B,1);

The result is a vector containing the results.

Hth
Darren.

Note: the Getting Started section in the Help may be very useful for you.
```
 0

```I must admit that this is a much neater solution than what I would imagine (involving some nasty loops).

Thank you both!
```
 0

3 Replies
898 Views

Similar Articles

12/7/2013 12:49:48 AM
[PageSpeed]

Similar Artilces:

matrix in a matrix
hallo there. I want to put a matrix that is 128X128 in a matrix that is 512X512 ( ones(512) ). what I want to do is to have the white image and above to put the second image ( a letter, A for example). I cant multiply cause they dont have the same dimensions. any ideas?? thanks in advance "th " <THOMITSU@YAHOO.COM> wrote in message <hsjabs\$bbc\$1@fred.mathworks.com>... > hallo there. > > I want to put a matrix that is 128X128 in a matrix that is 512X512 ( ones(512) ). > > what I want to do is to have the white image and above...;THOMITSU@YAHOO.COM> wrote in message <hsjabs\$bbc\$1@fred.mathworks.com>... > hallo there. > > I want to put a matrix that is 128X128 in a matrix that is 512X512 ( ones(512) ). > > what I want to do is to have the white image and above to put the second image ( a letter, A for example). that wasnt exactly what i meant.. I1=imread('Aneg.tif'); % this is the image with the letter I1=double(I1); I1=1-I1; % i make it with a white background and the letter is black I1=imresize(I1,0.25); % I resize it figure(1); imshow(I1,[]); I2=ones(512

2D matrix into 3D matrix
double to 244X306X80 double? The reason is because I would like to write this into ANALYZE format (.img/.hdr) which only works with 3D matrix. If I were to use a loop, how would I command it to do so? I would highly appreciate any assistance. Zeinab "Zeinab Al-Rekabi" <rekabi570@yahoo.ca> wrote in message <g40m26\$eji\$1@fred.mathworks.com>... > Hello to all, > > I am a recent user of Matlab and I have a project where I > have to read data from a scanner and obtain the necessary > processed images. I am stumbling upon a problem which I am > unable to solve. > > My initial data is 244X306X80 double, number of rows X > number of columns X number of slices respectively. I > obtained my necessary images by looking at a desired slice > say A(:,:,20). > > Using that slice A(:,:,20) I filtered the noise, multiplied > by a mask, etc.. where in the end I also got a final image > of 244X306 double. My problem is how do I convert this last > image which is 244X306 double to 244X306X80 double? The > reason is because I would like to write this into ANALYZE > format (.img/.hdr) which only works with 3D matrix. >

sorting matrix
Hi, I want to sort my matrix by its coulmn. I mean if I have matrix like [ 1 1 6 2 2 4 3 3 5] then I want it sorted as [ 2 2 4 3 3 5 1 1 6] namely sort it according to 3rd column, how can I achieve this ? thanks in advance mat = [ 1 1 6;2 2 4;3 3 5] [idx,idx] = sort(mat(:,3)); nmat = mat(idx,:) ruslan <akle@mynet.com> wrote in message <12908245.1227565676179.JavaMail.jakarta@nitrogen.mathforum.org>... > Hi, > > I want to sort my matrix by its coulmn. I mean if I have matrix like > [ 1 1 6 > 2 2 4 > 3 3 5] > then I want it sorted as > [ 2 2 4 > 3 3 5 > 1 1 6] namely sort it according to 3rd column, how can I achieve this ? > > thanks in advance sortrows(mat,3) HTH, John great ! thank you all

Creating matrix
Hi, I have a dataset that looks like Region Company 1 32 1 21 1 23 1 11 1 3 2 3 2 2 3 4 3 23 3 21 3 45 3 14 There are 25 regions and 45 companies in my dataset. I am trying to create a matrix 45 X 45 and with each cell containing the number of common regions the company pair does business. I tried breaking down the dataset... Dunn To sensible men, every day is a day of reckoning. ~John W. Gardner The important thing is this: To be able at any moment to sacrifice that which we are for what we could become. ~Charles DuBois Don't get your knickers in a knot. Nothing is solved and it just makes you walk funny. ~Kathryn Carpenter From: Mayukh Dass <mayukh.dass@GMAIL.COM> Reply-To: Mayukh Dass <mayukh.dass@GMAIL.COM> To: SAS-L@LISTSERV.UGA.EDU Subject: Creating matrix Date: Fri, 19 Jan 2007 11:49:28 -0500 Hi, I have a dataset that looks like Region Company 1 32 1

initializing a matrix
Hi all, I want to initialize row matrix A with 1 to 10, something like this : A = [1 2 3 4 5 6 7 8 9 10]; I wrote this code and it did work: A=[]; for i =1 : 10 A(1,i)=i; end But my question is that is there any simpler way than what I wrote to make the A matrix?I mean without this too much code. Thanks. Bita. Bita Mirshafiee <b.mirshafiee90@gmail.com> wrote in message <9b7dc92d-d990-462b-ab48-3eb4b3ae4a75@o13g2000vbo.googlegroups.com>... > Hi all, > > I want to initialize row matrix A with 1 to 10, something like this : > > A = [1 2 3 4 5 6 7 8 9 10]; > > I wrote this code and it did work: > > A=[]; > for i =1 : 10 > A(1,i)=i; > end > > > But my question is that is there any simpler way than what I wrote to > make the A matrix?I mean without this too much code. > > Thanks. > Bita. Why is A = 1:10; too much? You already know how to use the colon operator! So why use an explicit for loop? John

Transform a matrix
I've a matrix with values between 0.0 and 1.0 I must transform it so that the new values will be comprised between 0.0 and 255.0. Could anyone give me a suggestion? Best regards "elisa " <elisacarli@katamail.com> wrote in message <gkehol\$ep1\$1@fred.mathworks.com>... > I've a matrix with values between 0.0 and 1.0 > I must transform it so that the new values will be comprised between 0.0 and 255.0. > > Could anyone give me a suggestion? > > Best regards How about multiplying your matrix by 255? 255*0 = 0 255*1 = 255 elisa wrote: > I've a matrix with values between 0.0 and 1.0 > I must transform it so that the new values will be comprised between 0.0 and 255.0. Are the values strictly *between* 0.0 and 1.0 -- that is, are 0.0 and 1.0 themselves excluded? And in the output, are 0.0 and 255.0 to be excluded? And do the new values need to be integral, or would (for example) 254.3432432 be a possible output value? -- ..signature note: I am now avoiding replying to unclear or ambiguous postings. Please review questions before posting them. Be specific. Use examples of what you mean, of what you don't mean. Specify

Matrix as an argument
I need to pass a two dimensional matrix to a function. Function gets int ** but i cannot find appropriate input to function in main. in main mdelc(&ar1, 5, 5, 3); function prototype: void mdelc(int **ar1, int a, int b, int d) "Din�ay Ak��ren" <dincay@gmail.com> wrote in message news:1188681644.597585.136280@y42g2000hsy.googlegroups.com... >I need to pass a two dimensional matrix to a function. Function gets > int ** but i cannot find appropriate input to function in main. > > in main > mdelc(&ar1, 5, 5, 3); > > function prototype: > void mdelc(int **ar1, int a, int b, int d) > int **ar; ar = malloc(height * sizeof(int *)); for(i=0;i<height;i++) ar[i] = malloc(width * sizeof(int)); now you can use ar[y][x] = a; to set up the matrix values call mcdecl(ar, 5, 5, 3) no &. ar is already an int **. That's probably what the function mdecl is expecting. However it is not possible to be certain without more information. It might have different requirements for setting up the matrix. -- Free games and programming goodies. http://www.personal.leeds.ac.uk/~bgy1mm On 2 Eyl=FCl, 00:38, "Malcolm McLean"

Cell to matrix
Hello, I want to askk how I can convert a 1xsomething cell array into a 1Xsomething matrix. Any help will be appreciated. Thank you sylar <fasih_m@hotmail.com> wrote in message <624501819.63697.1272898594598.JavaMail.root@gallium.mathforum.org>... > Hello, > > I want to askk how I can convert a 1xsomething cell array into a 1Xsomething matrix. > Any help will be appreciated. > Thank you a hint: - your your CELL array consists of numeric entries, only help cell2mat; % also, see help cat; us

Comparing matrix
Okay, I am having problem with these codes below. The error I kept getting was: ??? Error using ==> eq Matrix dimensions must agree. Error in ==> VerbalSpan while text3==text2 %I dont understand why they did not just skip the while is size(text2) ~= size(text3) FYI: text2 appeared to be CANOE text3 appeared to be POLICE These are the codes: text3=str2mat(randsample(task(1:4))); if size(text3) == size(text1) while text3 == text1 text3=str2mat(randsample(task(1:4))); end end if size(text3) == size(text2... having problem with these codes below. The error I kept getting > was: > ??? Error using ==> eq > Matrix dimensions must agree. > > Error in ==> VerbalSpan > while text3==text2 > > %I dont understand why they did not just skip the while is size(text2) ~= > size(text3) > FYI: > text2 appeared to be CANOE > text3 appeared to be POLICE > > These are the codes: > text3=str2mat(randsample(task(1:4))); > if size(text3) == size(text1) > while text3 == text1 > text3=str2mat(randsample(task(1:4))); >

Exponential of a matrix
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi, There are several ways to compute the exponential of a matrix. One of these ways consists in using the spectral decomposition of the matrix, that the HP50g can do. As a result, why is EXP(A), where A is a matrix, not implemented? This would be very useful, especially for systems theory. - -- Merciadri Luca See http://www.student.montefiore.ulg.ac.be/~merciadri/ - -- Procrastination is the thief of time. -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (GNU/Linux) Comment: Processed by Mailcrypt 3.5.8 <http://mailcrypt.sourceforge.net/> iEYEARECAAYFAk2HQB0ACgkQM0LLzLt8MhyVhwCglF+9ofQFo2GWGaX70QuSYawZ K1MAnR+nKqBh/pGiWr62zOEz7zyJJkOy =miqb -----END PGP SIGNATURE----- On 21 Mar, 13:10, Merciadri Luca <Luca.Mercia...@student.ulg.ac.be> wrote: > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > Hi, > > There are several ways to compute the exponential of a matrix. One of > these ways consists in using the spectral decomposition of the matrix, > that the HP50g can do. > > As a result, why is EXP(A), where A is a matrix, not implemented? This >