To reply on Icrontic, register now.

It only takes 30 seconds.

Have an account? Sign in for less ads.

Forgot?
ldelgad8
Icrontic Convert
ldelgad8
15 Posts

Creating New Column from Calculation

If I have a matix:

1 12 13
2 42 43
3 22 23
4 32 33

How would I take an average of cols 2 & 3 and put those values in a new column, 4? I can calc the averages but it creates a second matrix.

Desired result:

1 12 13 12.5
2 42 43 42.5
3 22 23 22.5
4 32 33 32.5

If I do a max on col 4 to determine the largest value, how would I also pull off the corresponding id no, id is col 1 (max=42.5 and id is 2)?

thanks
shwaip
elaborate bot
shwaip
5,729 Posts
let's say your matrix is called A:

A(:,4) = (A(:,2) + A(:,3))/2

will put the avg in column 4

if your id's are always 1-based:

ind = find(A(:,4)==max(A(:,4)));
if not:
tmp = find(A(:,4)==max(A(:,4)));
ind = A(tmp,1);
__________________ my photostream for ic photography challenge

Anyone who wants dropbox, please use my referral link
ldelgad8
Icrontic Convert
ldelgad8
15 Posts
let's say your matrix is called A:

A(:,4) = (A(:,2) + A(:,3))/2

will put the avg in column 4

if your id's are always 1-based:

ind = find(A(:,4)==max(A(:,4)));
if not:
tmp = find(A(:,4)==max(A(:,4)));
ind = A(tmp,1);
Thanks again,I'm don't have matlab available right now so I can't try your code. Will this return the index or the actual value of col 1 for the corresponding max? If column 1 were just random id's would I get 6005 for the max value 42.5? What happens if two averages, col 4, were the same value?

1002 12 13 12.5
6005 42 43 42.5
3000 22 23 22.5
2454 32 33 32.5

Thanks
LD
Similar Threads
Thread Thread Starter Forum Replies Last Post
doom 3 problems davex General Hardware 23 17 Dec 2004 1:00pm
Creating a Counter in PHP (Difficulty: Beginner) Josh- Web & Digital Media 14 23 Oct 2004 9:32pm
Creating jar files shwaip Web & Digital Media 4 20 Jan 2004 7:50pm
Creating Users Slick Operating Systems 2 9 Jul 2003 9:03pm

Go Back   Icrontic Forums > Tech: Software > General Software > Matlab Help
Jump to
This Thread Search this Thread
Search this Thread:

Advanced Search


Current time: 1:12am (GMT)
Powered by vBulletin®
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Get Vanilla instead. Trust me.