Querying rows in a table, specific scenario
显示 更早的评论
I have road noise data in a table and I need to query it down to a balanced data set for analysis. For example, I only need Route_Surface Type combinations that have both levels of Speed. An example of my data and the desired output are below. Any suggestions on how to build this query?
%Data Inputs
ID = [1;2;3;4;5;6;7;8;9;10;11;12;13;14];
Route = {'IH10';'IH10';'IH10';'IH10';'IH10';'IH10';'US6';'US6';'IH35';'IH35';'US20';'US20';'US20';'US20'};
Surface = {'conc';'conc';'conc';'conc';'asph';'asph';'conc';'conc';'conc';'conc';'asph';'asph';'asph';'asph'};
%asph=asphalt, conc=concrete
Speed = [50;50;70;70;50;50;50;50;70;70;50;50;70;70];
%mph
SoundLevel = [51;54;75;76;52;60;68;63;79;80;49;51;66;68];
%Build the table
RoadNoise = table(ID,Route,Surface,Speed,SoundLevel);
RoadNoise =
ID Route Surface Speed SoundLevel
1 IH10 conc 50 51
2 IH10 conc 50 54
3 IH10 conc 70 75
4 IH10 conc 70 76
5 IH10 asph 50 52
6 IH10 asph 50 60
7 US6 conc 50 68
8 US6 conc 50 63
9 IH35 conc 70 79
10 IH35 conc 70 80
11 US20 asph 50 49
12 US20 asph 50 51
13 US20 asph 70 66
14 US20 asph 70 68
%Queried data (desired output)
Queried RoadNoise =
ID Route Surface Speed SoundLevel
1 IH10 conc 50 51
2 IH10 conc 50 54
3 IH10 conc 70 75
4 IH10 conc 70 76
11 US20 asph 50 49
12 US20 asph 50 51
13 US20 asph 70 66
14 US20 asph 70 68
采纳的回答
更多回答(1 个)
Bryan Wilson
2017-4-25
编辑:Bryan Wilson
2017-4-25
类别
在 帮助中心 和 File Exchange 中查找有关 Workspace Variables and MAT Files 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!