Filtering column 2 and keeping column 1

조회 수: 1 (최근 30일)
Jacob
Jacob 2025년 5월 14일
답변: Walter Roberson 2025년 5월 14일
I'm having an issue with filtering out data from column 2 that is below a certain desired output, but still keeping the time from column 1 to plot. I am fairly new to MatLab and it won't get rid of the negative outputs either.
This is my current code.
fs = 15;
rawData = xlsread('Total 4 Foot Lamp Lifecycle Testing.xlsx');
filteredData = lowpass(rawData(:,2),8,fs);
Any help is appriciated. Thank you.

답변 (1개)

Walter Roberson
Walter Roberson 2025년 5월 14일
mask = filteredData >= THRESHHOLD;
selected_time = rawData(mask,1);
selected_filtered_data = filteredData(mask);
However, if you proceed to
plot(selected_time, selected_filtered_data)
then plot() is going to draw right across the gaps. If your purpose is to plot and you want gaps in the plot, then you are better off using
mask = filteredData < THRESHHOLD;
filteredData(mask) = nan;
time = rawData(:,1);
plot(time, filteredData);
This inserts NaN in place of data that is below the threshold. When you go to plot() then plot() knows to leave gaps at all non-finite values (so gaps at NaN, at -inf, and at +inf)

카테고리

Help CenterFile Exchange에서 Signal Operations에 대해 자세히 알아보기

제품


릴리스

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by