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

### Finding mean for changing number of variables

• Email
• Follow

Hi, I'm trying to calculate the average PSD from a variable number of tests.  I use the "eval" function to rename i number of variables as they are entered.  (User enters no of sets, and variables are computed up to that set number using while loops). So I'm wondering how to convert this:

PSDtrimavg(:,i) = mean([PSD1trim(:,i),PSD2trim(:,i),PSD3trim(:,i)],2);

to compute the mean for any number of varialbes (PSDtrim_1...PSDtrim_i)  I've tried constructing them into cell arrays, using a while loop and creating a varying length array, but the mean function can't average the correct corresponding columns.

Here's an example from one of my "new variable" loops
while i <= sets
PSDavg = eval(['PSDAvg_' num2str(i)]);
PSDtrim = PSDavg(floor(0.5/df+1):floor(30/df+1),:);
eval(['PSDtrim_' num2str(i) '=PSDtrim;']);
freqtrim = freq(floor(0.5/df+1):floor(30/df+1));
i = i + 1;
end

Thanks for any possible help. One solution would be to creata an array of the variable names as a string and using eval to solve that, but I can't output just the variable name.

 0
Reply dmccorm2 (9) 6/21/2012 6:56:07 PM

See related articles to this posting

"Danny " <dmccorm2@nd.edu> wrote in message <jrvqo7$m72$1@newscl01ah.mathworks.com>...
>
>
> I use the "eval" function to rename i number of variables as they are entered.
===========

You're not kidding, are you?

 0
Reply mattjacREMOVE (3193) 6/21/2012 7:33:07 PM

"Danny " <dmccorm2@nd.edu> wrote in message <jrvqo7$m72$1@newscl01ah.mathworks.com>...
>
> I've tried constructing them into cell arrays, using a while loop and creating a varying length array, but the mean function can't average the correct corresponding columns.
=============

Elaborate on this and what you mean by "the mean function can't average the correct corresponding columns". If your data sets existed as cell array elements data{i}
why couldn't you do this

result=cellfun(@mean,data,'uni',0);

 0
Reply mattjacREMOVE (3193) 6/21/2012 7:40:08 PM

No, but I did manage to get it to work by creating variable matrices of corresponding columns, and just finding the mean  across.  Since there are only 5 channels of data, but potentially "infinite" tests.  However, I still feel there is a more forward way of doing it.

 0
Reply dmccorm2 (9) 6/21/2012 7:47:07 PM

So the way the equation is set up is to average the corresponding columns of each PSD.  In other words, it averages column 1 of PSDtrim_1 with column 1 of PSDtrim_2 to make an averaged column, and then proceeds with column 2 of PSDtrim_1...  The way it's stored in the cell array is each matrix entered as it's own column.  Now the cell array could be anything from {1,2} to {1,99} and the mean function can't select the correct column from each subcell in a while loop. Simply put I might want to average a, b, c, d.  but the mean function is only set up to do a,b,c.  Another time I might want to do a,b, and mean(a,b,c) wouldn't fix that.

 0
Reply dmccorm2 (9) 6/21/2012 7:52:06 PM

"Danny " <dmccorm2@nd.edu> wrote in message <jrvu16$7ri$1@newscl01ah.mathworks.com>...
>
>
> In other words, it averages column 1 of PSDtrim_1 with column 1 of PSDtrim_2 to make an averaged column, and then proceeds with column 2 of PSDtrim_1...
==============

For that to be possible, all matrices PSDtrim_i would have to be the same size. So then why couldn't you instead store your PSDs into different slices of a 3D array, i.e., so that instead of PSDtrim_i, you would have PSDtrim(:,:,i)

Then, to average together corresponding columns, all you would need to do is

result=mean(PSDtrim,3);

If this still doesn't apply to your situation, I think we need you to show us some miniature examples of PSDtrim_i, for i=1,2,3 and show what you want the output to be.

 0
Reply mattjacREMOVE (3193) 6/21/2012 8:03:06 PM

> For that to be possible, all matrices PSDtrim_i would have to be the same size. So then why couldn't you instead store your PSDs into different slices of a 3D array, i.e., so that instead of PSDtrim_i, you would have PSDtrim(:,:,i)
>
> Then, to average together corresponding columns, all you would need to do is
>
> result=mean(PSDtrim,3);
===================================================

That worked perfectly, thank you.  Pretty obvious, but for whatever reason I never considered putting them 3D, probably because the original was in 2D and I was just trying to loop it.

 0
Reply dmccorm2 (9) 6/21/2012 8:21:07 PM

6 Replies
27 Views

Similar Articles

12/11/2013 2:56:49 PM
[PageSpeed]

Similar Artilces:

Finding the biggest number out of 8 variables
Hi All Does anybody know of an easy way to find out which variable has the highest value out of 8 variables? For example, I have these values in 8 vars: 3 0 7 30 37 17 0 7 Although from a human's perspective it's easy to see that the 5th var has the highest value, how can I chose the appriopriate var programmatically? Thanks Sun, 31 May 2009 14:26:37 +0100 from Mojo <please@dont.spam.com>: Ironic choice of fake email address, given that you yourself spammed this message. > Does anybody know of an easy way to find out which variab...

Test vote 2005: 1.0 shall mean fp-number ONE, not double-number TEN
Just for fun (and perhaps useful for Forth-200x): Extracts from the current standard docs say: 8.3.2 Text interpreter input number conversion When the text interpreter processes a number that is immediately followed by a decimal point and is not found as a definition name, the text interpreter shall convert it to a double-cell number. A.12.3.7 Text interpreter input number conversion The Technical Committee has more than once received the suggestion that the text interpreter in Standard Forth systems should treat numbers that have an embedded decimal point, but no exponent, as floating-poi...

Finding unknown variables
Greetings, My daughter received this problem to solve. She is presently in 5th grade. We have tried to solve it, to no avail. Thanks you for your help, here it is: c=4 d-a=i b-c=g ac+ic=de sg-de=hi We need to know the values of all the variables, how do we go about it? Each letter represents a digit, from 0 to 9. It's probably required that they must all be different. Calculators are not amenable to this type of problem. You have to do this by brute force, bit by bit. d-a=i b-c=g So a<d, 4=c<b, g<=5 (since b<=9) ac+ic=de, so a4+i4=de; e=8, a+i=d (but we already kn...

how to find a port number
Does anyone know if it is possible to find a port number of a switch from a IP or MAC address? If that makes sense? On Jun 25, 10:03 am, dan_flemin...@hotmail.com wrote: > Does anyone know if it is possible to find a port number of a switch > from a IP or MAC address? If that makes sense? 1. On router that owns the subnet: show arp | include a.b.c.d 2. Then take the resulting mac from the above command, put in format aa-bb-cc-dd-ee-ff 3. Go to core switch: show cam aa-bb-cc-dd-ee-ff 4. Should tell you the port it is on, including if it is off a trunk. If it is off a trunk, d...

find numbers in BST
Given a binary search tree, how to find two numbers that can add up toa given number K? usgog@yahoo.com schrieb:> Given a binary search tree, how to find two numbers that can add up to> a given number K?nice homework .. have much fun with it.. usgog@yahoo.com wrote:> Given a binary search tree, how to find two numbers that can add up to> a given number K?Its quite simple, start at both ends and work your way toward K/2, or start at K/2, and work your way out.-- Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/> Daniel Pitts <newsgroup.spamfilter@virtualin...

changing HEX into a number
why doesn't this vi work? i am receiving 3 hex bytes from a board, and i need to view it as a numerical value. i know that the hex "F9FFFF" is equal to 16,383999 when i look at it on the calculator. &nbsp; i receive 3 bytes, convert it to a number, and display it. it seems like a simple task....... &nbsp; thanks,,,, &nbsp; im using labview 7.0 decoder testing.vi: http://forums.ni.com/attachments/ni/170/165124/1/decoder testing.vi Just yesterday somebody posted another question kinda like this, the solution of which involved a nifty use of the Type Cast function.&a...

Idenfity numbers in variables
Hello, I have a trouble and I don't know how to solve it. I am working with molecules and each molecule has a number of atoms. I obtain each atom spliting the molecule. Ok. It is fine and I have no problem with it. The problem is when I have to work with these atoms. These atoms usually are only a letter but, sometimes it can also contain one o more numbers. If they contein a number I have to manipulate them separately. If the number was allways the same I know how to identify them, for example, 1: atom = 'C1' if '1' in atom: print 'kk' But, how can I do to i...

Finding unused variables
i have a set of variables declared in Working storage section. i want to find out unused varialbes in Procedure Division using REXX Language. Thanks in advance. Regards ------- Suresh Chandra G. That sounds like COBOL Send me the source and I'll think about it Walter ( pachl at chello.at ) "Suresh" <surresh.chandra@gmail.com> schrieb im Newsbeitrag news:1121171822.418811.211760@g49g2000cwa.googlegroups.com... >i have a set of variables declared in Working storage section. > i want to find out unused varialbes in Procedure Division using REXX > Language. > ...

changing const variables
guys, If I declare a const variable and then try to change it as follows; const int i=5; i = 10; What would be the behaviour? Should compiler give compilation error or Warning ? Or, would I get a run time error (some exception as I am trying to change a const variable) ? can compiler put const variables in read only memory ? I tried this on multiple platforms using different compiler and I am getting different results, that is why I am asking this here. I want to know the correct behaviour as per the standard C. Again, thanks a lot for any help ... junky_fellow@yahoo.co.in wrote: ...

Changing pseudocode numbering
I'm using the pseudocode package, and its counter (\thepseudocode) is defined as \renewcommand{\thepseudocode}{\thesection.\arabic{pseudocode}} However, I would like it to be based on the current chapter, instead of the section: \renewcommand{\thepseudocode}{\thechapter.\arabic{pseudocode}} If I just change that line in the package file, the pseudocode algorithms in my text are numbered correctly (next to the code listing, it says "Algorithm 3.1", for example), but references in the text (\ref{alg1}) show up as "3.2.1", for example. Why is this? I don't...

Finding a Number in Matlab
Is there a way to find a location of a specific number in a matrix. For instance, if have the following matrix: A = [1 3 2] [9 5 7] [8 4 6] Is there anyway to find the location of 5 (i.e. for matlab to return something like (2 2))? Thank You Leif Sandager I do not know if you can get the (2,2) but you can know that its index position is 5 by using find(a==5) you will get ans=5 which means it is in the fifth position. Similarly find(a==4) will give you an answer of 6. It counts them top to bottom and left to right, column by column. [I,J] = find(A==5) Note that if there is...

Change length of variable
I have a form that has a function on that pulls the user name that was used to log on to the network. The problems is that variable is pulling back the user name but also a square at the tend, which I assume is some type of control or other charcter. I need to removed that from the end of the string. How would I do this? Michael Charney *** Sent via Developersdex http://www.developersdex.com *** Don't just participate in USENET...get rewarded for it! Left(varName,Len(varName)-1) P "Nothing" <me@you.com> wrote in message news:3fa14f90$0$199$75868355@news.frii.net... &g... change string into variable when going to index.php?headlines=Macsanomat i want to use the$Macsanomat instead of Macsanomat (the string) this is needed to declare $Macsanomat into a loop. piece of the code: //------$Macsanomat['naam'] = "Macsanomat"; $Macsanomat['vlag'] = '<img src="finland.gif>';$Macsanomat['tekst'] = "<b>News</b> powered by "; $Macsanomat['id'] = '714'; if ($headlines !="") { echo $headlines['vlag'].'<a href="'.$headlines['id'].'>'.$headlines['naam&... mask change by variable Hey there, i would like to change the appearence of a subsystems mask depending on a calculated value inside the subsystem. For example changing the background color or the icon of the mask. Slowly, my modells are getting to complex for an easy troubleshooting and this should help. Is there a easy way and -most important- who knows and can help? Thanks in advance! J�rgen ... number of input (variables) Is there a limitation in number of input (variables). Say we have 100 input variable.what would it effect the number of neuron in hidden layer or the number of hidden layer itself? Say we could produce enough data for training. On Oct 23, 11:03=A0pm, amir <beh.am...@gmail.com> wrote: > Is there a limitation in number of input (variables). Given a set of output variables there is usually a limit to the number of necessary inputs. Whether or not those inputs or an alternative set are available is one issue. Other issues are: Whether or not a given set of inputs contains en... calling find with variables Hi, I am using a shell script called from anacron to adjust file permissions in my home directory. I am using "find ~ <restriction> -exec chmod <something>" I have a big line of restrictions which I therefore wanted to put into an environment variable: prune="-not -regex ~/\.bin -not -regex \.DCOP.* <...>" and want to call find ~$prune -type d -exec chmod 750 {} \; However, find complains that it wants all folders specified at the beginning. Whats wrong here? Thank Uwe -- On 8/14/2003 5:20 AM, Uwe Mayer wrote: > Hi, > > I am using ...

The same operation on a number of variables.
I have a big number of variables, mostly data from the form. I want to convert all empty variables into "NULL". Obviously for each variable I could write: if (empty($a))$a=="NULL"; if (empty($b))$b=="NULL";...and so on.... But let's say I have like a hundred of them. Is there any way to write it in just a few rows ??? Thanx In article <1n9rwomx8jqem\$.dlg@www.okozaoko.pl>, Pawe? <pmg3@op.pl> wrote: > I have a big number of variables, mostly data from the form. > I want to convert all empty variables into "NULL". > Obviously...

changing auto numbers
We have a database with 1600+ records in it. They are linked across 7 tables by an ID type autonumber. Now we want(not I want LOL) to remove the first 1200 records no problem but they also want the ID to be reset to 1,2,3 ... this would mean that record 1234=1 1235=2 With the id being linked across 7 tables with relationships...one to one and some with one to many..can this be done without messing up the links? thanks for info I have never tried this before Jerry On Wed, 24 May 2006 13:01:13 GMT, sparks <jstalnak@swbell.net> wrote: This is a FAQ. Search at groups.google.co...

How to change table numbering
I want to change the appearance of table numbers in the appendix to A. 1, A.2, ... (same for figure). The code for changing enumi didn't work. This is what I tried: \setcounter{table}{0} \renewcommand{\labeltable}{A.\thetable} pdflatex said \labeltable is undefined. Harvey Greenberg <hjgreenberg@gmail.com> writes: >I want to change the appearance of table numbers in the appendix to A. >1, A.2, ... (same for figure). The code for changing enumi didn't >work. This is what I tried: > >\setcounter{table}{0} >\renewcommand{\labeltable}{A.\thetable} > >pdf...

Dynamic changing of variables
Hi, assume the following code lines: DynamicModule[{a, b = 0}, a = Dynamic[Sin[b]]; Column[{ Dynamic[a], Slider[Dynamic[b], {0, 2*Pi}] }] ] In order to update "a" with the actual value of Sin[b] I need Dynamic around it. Unfortunately, now the variable "a" is invisibly wrapped and completely useless for further calculations. I'm not able to calculate even a+1 inside the DynamicModule. DynamicModule[{a, b = 0}, a = Dynamic[Sin[b]]; Column[{ Dynamic[a+1], Slider[Dynamic[b], {0, 2*Pi}] }] ] If I'm not j...