How to select a data set from columns having using criteria?

I have 5 columns in the file mycolumns. They all have the same dimension. I would want to reduce the number of rows of all the columns by same amount by selecting the row that first meet the condition where the elements of columns "acc<10" and "C<20". I am interested in the first row meeting the criteria to the end of rows of each column. Again I would want to know the time the first row met the criteria and then subtract for the initial time,thus, time(1,1) to obtain the number of minutes it took for the criteria to be met. Thanks for you support.

 채택된 답변

Star Strider
Star Strider 2015년 6월 27일
편집: Star Strider 2015년 6월 27일
EDIT — Edited to produce only the data from the time criteria are met until the end of the data.
See if this does what you want:
D = load('mycolumns.mat');
Ix1 = find((D.acc < 10) & (D.C < 20));
t0 = D.time(Ix1(1)); % First Time Criteria Met
new_time = D.time(Ix1:end)-t0; % Time From ‘t0’ To End
new_acc = D.acc(Ix1:end); % Corresponding ‘acc’
new_C = D.C(Ix1:end); % Corresponding ‘C’
figure(1)
plot(new_time,new_acc, new_time,new_C)
grid
legend('acc', 'C', 'Location','NW')
xlabel('time')

댓글 수: 4

You could also use the 'first' option in find:
% Find the index where the criteria was first met.
indexOfFirst = find((D.acc < 10) & (D.C < 20), 'first', 1);
% Now, knowing that index, extract the time
% when the criteria was first met from the "D" structure.
t0 = D.time(indexOfFirst);
Good point. However, I wanted to leave ‘Idx1’ as an index vector of all the data that met the criteria, since it is not clear from the Question if OP wants only the first index, or the indices of all the values that meet the criteria, and then resetting the D.time(Ix1) as ‘t0’.
AbelM Kusemererwa
AbelM Kusemererwa 2015년 6월 27일
편집: AbelM Kusemererwa 2015년 6월 28일
Image Analyst, reference the plot I also need the data from the vertical red line(showing the first time the criteria is met) to the end for all the 5 column. Will new_A = D.A(Ix1:end); % Corresponding ‘A’ and new_B = D.B(Ix1:end); % Corresponding ‘B’?
I edited my code to provide both ‘t0’ and the data you requested in my current code. It should do what you want. Note that ‘new_time’ is reset so that ‘t0’ is zero, because that’s what I thought you requested. If you want to keep the ‘old’ time, ‘new_time’ becomes:
new_time = D.time(Ix1:end);
All the data plotted in figure(1) have to be the same lengths, so it is necessary to redefine all of them.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Azzi Abdelmalek
Azzi Abdelmalek 2015년 6월 27일
편집: Azzi Abdelmalek 2015년 6월 27일
v=[time A B C acc ];
idx=v(:,5)<10&v(:,4)<20;
out=v(idx,:)
Time_criteria=v(find(idx,1),1)

댓글 수: 2

AbelM Kusemererwa
AbelM Kusemererwa 2015년 6월 27일
편집: AbelM Kusemererwa 2015년 6월 28일
Azzi, the "out" gives me only the once that meet the criteria (sorting for the once that me the criteria). I am only interested in the data set from the first row that meet the criteria to the end. The criteria is to throw away the first few rows until the first row that meets the criteria.
v=[time A B C acc ];
idx=find(v(:,5)<10&v(:,4)<20,1);
out=v(idx:end,:)
out(:,1)=out(idx,1)-v(idx,1)

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by