How to approach iterative data reading?

I'm working with a dataset that has 3 different arrays I'm interested in plotting: time, accel, and gcamp. They are all of equal size.
I'm using the accel variable as a threshold detector, where I define an arbitrary threshold under which any data I ignore. Anything above that threshold I use the index of that data point to grab the equivalent data points from time and gcamp.
How can I store this data in one structure so that I can iterate through it and generate statistics/plots about only the thresholded data points?
Something like:
time = [rand(1, 5000)];
accel = [rand(1,5000)];
gcamp = [rand(1,5000)];
sd = std(accel);
threshold = sd;
dumb = [];
for i = 1:length(accel);
if accel(i) > threshold;
dumber = [time(i), gcamp(i)];
dumb = [dumb, dumber];
end
end

 採用された回答

Paul
Paul 37分 前

0 投票

Hi Eric,
Use logical indexing.
time = [rand(1, 5000)];
accel = [rand(1,5000)];
gcamp = [rand(1,5000)];
sd = std(accel);
threshold = sd;
dumb = [];
for i = 1:length(accel);
if accel(i) > threshold;
dumber = [time(i), gcamp(i)];
% dumb = [dumb, dumber];
dumb = [dumb; dumber];
end
end
index = accel > threshold;
foo = [time(index);gcamp(index)].'; % transpose to match dumb
isequal(foo,dumb)
ans = logical
1

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeMAB Modeling Guidelines についてさらに検索

質問済み:

2026 年 4 月 3 日 0:10

回答済み:

2026 年 4 月 3 日 2:00

Community Treasure Hunt

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

Start Hunting!

Translated by