Re: List manipulation
- To: mathgroup at smc.vnet.net
- Subject: [mg44578] Re: List manipulation
- From: Sujai <NOsujaikumarSPAM at ameritech.net>
- Date: Sat, 15 Nov 2003 02:05:08 -0500 (EST)
- References: <bp22ti$219$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
> I have a For loop storing data in a {x,y} list (where x is time and y is
> temperature), and I would like to get the x at which a certain threshold
> y occurs without stoping the loop.
hi.
you could get this value inside the for loop itself using a standard
procedural algorithmic technique such as:
1. first set a flag variable Found = False outside the loop.
2. within the for loop, after you calculate the {time, temp}, you could
write an If statement like:
If [temp > threshold && Found == False,
(resultTime = time;
Found = True;)]
the other, more elegant (but possibly equally computationally expensive)
way could be to t
am assuming that your final data list looks like:
data = { {time1, temp1}, {time2, temp2}, ...}
Select[data, (#[[2]] >= threshold)&, 1] [[1,1]]
This statement creates a list of the first 1 element (thats what the , 1
does inside the Select statement) that meets the condition that its
second part (the temp) is greater than a threshold. The [[1, 1]] at the
end pulls out the first part of the first (and only) element of this list.
Hope this helps.
- sujai