How to use IF statements to find data greater than or equal to a certain amount

18 次查看(过去 30 天)
If you have a large amount of data, tens of millions of rows of data, how can you use IF statements in MATLAB to find specific data points that spike above a certain threshold?
Lets say for example you have a load of capacitance data against time. And you wan to find where the data spikes above 1 Farad. An example data table:
Time, Capacitance
1 uS, 0.3
2 uS, 0.5
3 uS, 0.8
4 uS, 1
5 uS, 1.3
6 uS, 1.4
7 uS, 1.2
8 uS, 0.9
9 uS, 0.5
You want to sift through this table and create a new variable that only includes data where the capacitance exceeds 1 Farad

采纳的回答

Karim
Karim 2022-9-19
编辑:Karim 2022-9-19
see below for a demonstration
Time = [1 2 3 4 5 6 7 8 9]';
Capacitance = [0.3 0.5 0.8 1 1.3 1.4 1.2 0.9 0.5]';
MyTable = table(Time,Capacitance)
MyTable = 9×2 table
Time Capacitance ____ ___________ 1 0.3 2 0.5 3 0.8 4 1 5 1.3 6 1.4 7 1.2 8 0.9 9 0.5
% delete variables, just to show that we work with the data from the table
clearvars Time Capacitance
% set a treshold value
Treshold = 1;
% use some logice to find the values larger then the treshold (if you want
% to include it use >= instead of >
KeepMe = MyTable.Capacitance > Treshold;
% extract a part of the table using the logical array
NewTable = MyTable( KeepMe , : )
NewTable = 3×2 table
Time Capacitance ____ ___________ 5 1.3 6 1.4 7 1.2
  6 个评论
Voss
Voss 2022-9-19
编辑:Voss 2022-9-19
@AluminiumMan: You left off the second subscript, like the error message suggests:
A=B.C(C.Capacitance>Threshold,:);
% ^^ you need this part
Notice that @Karim's answer has it:
NewTable = MyTable( KeepMe , : )
Here's a demo with your mat file and variables, as given:
S = load('CapacitanceData.mat');
B = struct('C',S.CapacitanceData.RecordedCapacitanceData);
C = B.C;
Threshold = 1;
A=B.C(C.Capacitance>Threshold,:)
A = 3×2 table
Time Capacitance ____ ___________ 3 1.3 4 1.6 7 1.3

请先登录,再进行评论。

更多回答(1 个)

Chunru
Chunru 2022-9-19
c = randn(20,1) % random data
c = 20×1
-0.1315 1.3920 0.3866 0.1342 0.7914 -0.5643 2.9497 -0.1842 -0.3139 0.3103
c1 = c(c>1)
c1 = 2×1
1.3920 2.9497
  5 个评论

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Tables 的更多信息

标签

产品


版本

R2019b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by