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
0 个评论
采纳的回答
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)
% 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 , : )
6 个评论
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
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,:)
更多回答(1 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!