I want to add a column that counts the passes for this test. When the values in the first column are between 0-300 seconds, I want to consider that pass 1, etc.

1 次查看(过去 30 天)
I want to add a column that counts the passes for this test. When the values in the first column are between 0-300 seconds, I want to consider that pass 1, etc.
I figured out how to add a new column:
%Add new columnm to mark passes
passestest= zeros(size(CETR,1),1);
CETR=[CETR,passestest];
I would then like to find the averages for each of the passes (averages of all rows in pass 1).

回答(2 个)

Walter Roberson
Walter Roberson 2018-1-25
Possibly you want to use histcounts(), passing in edges like [0 300 450 ....] to count 0 <= x < 300, 300 <= x < 450, and so on
  2 个评论
Marian Kennedy
Marian Kennedy 2018-1-25
编辑:Walter Roberson 2018-1-25
Is there a way to automate this process?
for i=1:numel(CETR1(:,1)) %numel means number of elements in CETR1(:,1)
if CETR1(i,1)<300
CETR1(i,12)=1;
elseif CETR1(i,1)<600
CETR1(i,12)=2;
elseif CETR1(i,1)<900
CETR1(i,12)=3;
end
end
Steven Lord
Steven Lord 2018-1-25
The histcounts function returns bin counts as its first output and bin membership numbers in its third output. The discretize function returns bin membership numbers in its first output. In this case I'm going to get histcounts tell me what edges it used and reuse those edges in discretize. If you know the bin edges you want to use, you can specify them in either histcounts or discretize.
x = randperm(100, 25);
[bincounts1, edges1, binlocations1] = histcounts(x)
binlocations2 = discretize(x, edges1)
isequal(binlocations1, binlocations2) % true
From your description you're more interested in binlocations1 (or binlocations2, since they're the same) than bincounts1.

请先登录,再进行评论。


Guillaume
Guillaume 2018-1-25
编辑:Guillaume 2018-1-25
You can do the discretisation (as that's what you want is called) and the addition as a new column all in one go:
CETR1(:, end+1) = discretize(CETR1(:, 1), [0 300 600 900])
No loop needed of course.

类别

Help CenterFile Exchange 中查找有关 Oceanography and Hydrology 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by