从Mathematica中的表中选择数据 [英] Selecting data from a table in mathematica

查看:470
本文介绍了从Mathematica中的表中选择数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编写一个函数,该函数将选择满足条件的表中的第一个元素.例如,如果为我提供了下表,第一栏为时间,第二栏为受疾病感染的人数,那么我想编写一个参数,该参数将返回至少100人被感染的时间.

I'm trying to write a function that will take select the first element in the table that satisfies a criteria. For example, if I am given the following table with times in the first column and number of people infected with a disease in the second, I want to write an argument that will return the time where at least 100 people are infected.

0   1
1   2
2   4
3   8
4   15
5   29
6   50
7   88
8   130
9   157
10  180
11  191
12  196
13  199
14  200

因此,从这张表中,我希望争论者告诉我,在8秒时,至少有100人被感染.我尝试使用SELECT来执行此操作,但是我不确定如何将SELECT与2列的表一起使用,并使其根据第二列中的条件在第一列中返回值.

So from this table, I want the arguemnt to tell me that at 8 seconds, at least 100 people were infected. I tried using SELECT to do this, but I'm not sure how to use SELECT with a table of 2 columns and have it return a value in the first column based on criteria from the second column.

推荐答案

您还可以使用简单的NestWhile

You can also use a simple NestWhile

data = {{0,1},{1,2},{2,4},{3,8},{4,15},{5,29},{6,50},{7,88},{8,130},{9,157},{10,180},
 {11,191},{12,196},{13,199},{14,200}};
NestWhile[# + 1 &, 1, data[[#, 2]] < 100 &] - 1

这篇关于从Mathematica中的表中选择数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆