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

4 ビュー (過去 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
AluminiumMan
AluminiumMan 2022 年 9 月 20 日
Its working. Thank you for your help

サインインしてコメントする。

その他の回答 (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 件のコメント
AluminiumMan
AluminiumMan 2022 年 9 月 19 日
Sure. Please find data attached
AluminiumMan
AluminiumMan 2022 年 9 月 20 日
Its working. Thank you for your help

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

タグ

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by