how can i count the values above a threshold of random data and represent on a graph of time vs. rate ?
2 次查看(过去 30 天)
显示 更早的评论
the # of occurrences (Rate) should be represented right in the middle of time slot. say 6 values above threshold within 0-1 second. 6 should be at .5s in the graph.
any help is appreciated thanks.
10 个评论
Image Analyst
2013-11-17
OK, how can we help? (Look at what you've supplied us with - would you be able to answer that?) http://www.mathworks.com/matlabcentral/answers/6200-tutorial-how-to-ask-a-question-on-answers-and-get-a-fast-answer
Walter Roberson
2013-11-18
What information is available? Is the data provided? Is there a time provided for each individual data item? Is there an implicit sampling rate (e.g., 15 samples makes up one second) ? Is anything else being plotted as well?
Ana-Patricia Lopez
2013-11-18
I have chosen a random set of numbers t and a function y. After these values are plotted I have told matlab to highlight the values above a threshold of 0.5. I am having a hard time getting a graph representation [or histogram] that shows the number of values that are above the threshold throughout time. Time slots can be 0-1,1-2,3-4 seconds.. until 20s for example. so for example, if I have 6 values that are above the threshold 0.5 within 0-1 second. I want to be able to represent a graph of time vs rate where I can see a dot in y=6 in x=0-1second and that the dot is located in the middle of the timeslot. so, x=0.5...
so far I have written a code that shows non-zero values of t and y. I just need to count them and represent in graph.
let me know if you would like to see the code I have so far.
thanks
Ana-Patricia Lopez
2013-11-18
编辑:Walter Roberson
2013-11-18
Yes, t represents time indeed.
I thought I would need to also care about non-zero values of t, but I am really just interested on non-zero values of y above 0.5...
i basically need some graph representation that tells me: this is how many points of y fell within 0-1second . im not really worried about what the coordinates are. only the # of occurrence.
here is the code I have so far.
close all
clear all
clc
THRESHOLD=0.5;
t = 0:pi/100:6*pi;
y=sin(t);
P=[t' y'];
y_values=P(:,2);
Y=y_values>THRESHOLD;
Q=P(Y,:);
figure(1)
hold on
plot(P(:,1),P(:,2))
plot(Q(:,1),Q(:,2),'.r')
xlabel('time')
ylabel('f(t)')
for i=1:lenght(P(:,2))
P_NEW(i,1)=P(i,1);
if P(i,2)<THRESHOLD
P_NEW(i,2)=0;
else if P(i,2)>=THRESHOLD
P_NEW(i,2)=P(i,2)
end
end
end
thanks!
Umair Nadeem
2013-11-18
Are you trying to count the number of values for each cycle i.e. crest of wave or over a time interval? Beacsue there are intervals over which there is no value above or equal to 0.5. ??
Ana-Patricia Lopez
2013-11-20
umair - yes, i want to count only the values above the threshold and in this case, there are two crests with some points above. i am intersted on those values.
Ana-Patricia Lopez
2014-1-7
编辑:Ana-Patricia Lopez
2014-1-7
I might be missing something. The plot with the graph showing the values above threshold does not seem to match the plot with the counts. I would like to match the bin ranges just so that I could use the second plot to know how many values fall within a certain amount of time. So, pretty much, match the x-range (bin range) that represents time in the first plot, to the x-range (bin range) from the second plot. As you can see, the second plot shows markers where there are not even numbers above the threshold (which is .5)... Any help is appreciated. thanks.
This is what I have so far:
close all
clear all
clc
THRESHOLD=0.5;
%t = 0:pi/100:6*pi;
t=0:pi/100:7;
y=sin(t);
P=[t' y'];
y_values=P(:,2);
Y=y_values>THRESHOLD;
Q=P(Y,:);
figure(1)
hold on
plot(P(:,1),P(:,2))
plot(Q(:,1),Q(:,2),'.r')
xlabel('time')
x=t;
binranges=(0:1:7);
BR= (binranges');
[bincounts, ind]=histc(x,binranges);
ind(:)=(ind');
counts=accumarray(ind(:), y(:) >=THRESHOLD);
figure
bar(BR,bincounts,'histc')
%plot(BR,bincounts,'+r');
plot((BR(1:end-1)+BR(2:end))/2, bincounts(1:end-1),'+r')
set(gca,'XTick',1:length(t));
set(gca,'YLim',[0, 40])
xlabel('bin ranges')
ylabel('Counts')
Ana-Patricia Lopez
2014-1-7
i will post a new question for a new answer since this question was already answered with what I needed. unless you prefer to answer this question here, that is fine with me.
Ana-Patricia Lopez
2014-1-7
采纳的回答
Walter Roberson
2013-11-18
Apply histc() with evenly-distributed bins (of the desired time interval), applying it to your times. Use the two-output form of histc(), and then the second output will tell you the bin number. At that point,
counts = accumarray(bin_number(:), y(:) >= THRESHOLD);
This will give you the number of occurrences for each bin.
After that it just becomes a matter of text()'ing the counts into place at the mid-point of each interval.
6 个评论
Ana-Patricia Lopez
2013-11-20
Thanks for your reply Walter. It seems like that is what i need however, i am having trouble setting it up. when you say, "two-output form of histc() do you mean: bincounts=histc(x,binranges) and that the second output as in "binranges" will tell me the bin number?
thanks
Image Analyst
2013-11-20
No. histc() can supply two outputs . He wants you to accept both of them , not just one like you did.
Ana-Patricia Lopez
2013-11-23
@image analyst - your answer is not clear to me.
I am a matlab beginner.
My question is regarding those two outputs.I do not know which two outputs histc() gives. That is why I asked. As soon as this is clear to me, then I already know that the second output gives the bin number.
Image Analyst
2013-11-23
[n, bin] = histc(x, edges);
n and bin are the two outputs, x and edges are the two inputs.
You said " the second output as in "binranges" " - that is not correct. binranges is an input, not an output. Notice how it is being passed IN to a function, not being returned out of a functions. The outputs are on the left side of the equal sign, and the inputs are inside the parentheses after the function name.
Ana-Patricia Lopez
2013-11-30
thanks for your reply @image analyst - really helpfull
When I proceed and run accumarray, I get this:
Error using accumarray Second input VAL must be a vector with one element for each row in SUBS, or a scalar.
I have tried plugging in y, Y, y_values and still get the same error:
counts=accumarray(ind(:), y_values(:));
I was not able to find a clear solution on the web. any thoughts?
-thanks
Ana-Patricia Lopez
2013-12-28
the histc() worked fine!
Im just trying to shift the counts right at midpoint of x ranges. any help is appreciated. thanks
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Polar Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!发生错误
由于页面发生更改,无法完成操作。请重新加载页面以查看其更新后的状态。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
亚太
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)