필터 지우기
필터 지우기

How to find the x value from cumsum

조회 수: 5 (최근 30일)
K
K 2012년 12월 21일
Hi, I plotted a cumulative sum in Matlab. Is there any where for me to get the value of x from the plot(value of y is known)?

채택된 답변

Image Analyst
Image Analyst 2012년 12월 21일
K:
x never equals 7000. Not sure which bar graph you were looking at but none of them have an x value of 7000. Now if you want the x value where y first exceeds 7000, then you can look at the last few lines I tacked on to the bottom of their example (which is the top several lines):
clear
clc;
workspace; % Make sure the workspace panel is showing.
format longg;
format compact;
fontSize = 20;
x = -2.9:0.1:2.9;
y = randn(10000,1);
figure(1)
hist(y,x);
xlabel('x', 'FontSize', fontSize);
ylabel('y', 'FontSize', fontSize);
title('Histogram', 'FontSize', fontSize);
% Calculate number of elements in each bin
n_elements = histc(y,x);
% Calculate the cumulative sum of these elements using cumsum
c_elements = cumsum(n_elements)
% Plot the cumulative distribution like a histogram using bar:
figure(2)
bar(x,c_elements,'BarWidth',1);
grid on;
% Enlarge figure to full screen.
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
% Find out x when c_elements = 7000
% first find the index.
x7000Index = find(c_elements >= 7000, 1, 'first')
% Then find the x value for that index.
x7000 = x(x7000Index);
message = sprintf('The cumulative sum first exceeds 7000\nat an x value of %.1f', x7000);
uiwait(msgbox(message));
  댓글 수: 1
K
K 2012년 12월 21일
Thank you very much. Yes, I made some error in my writing. I want the x value where y first exceeds 7000. Thank you again for your help.

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

추가 답변 (3개)

Jan
Jan 2012년 12월 21일
It depends on what you exactly want...
Actually the X-values are trivial:
data = rand(1, 100);
y = cumsum(data);
lineH = plot(y);
% Now the X-values are:
x = 1:numel(y);
% You can obtain them explicitly:
x2 = get(lineH, 'XData');

Azzi Abdelmalek
Azzi Abdelmalek 2012년 12월 21일
x=1:10
y=cumsum(x)
% for y=15
x0=x(find(y==15))
  댓글 수: 1
K
K 2012년 12월 21일
Thank you for your reply. Actualy I did the cumsum from this example: http://www.mathworks.co.uk/help/matlab/ref/histc.html
Based on the bar graph, I need to find the y value when x=7000
I tried your solution. But it give different value.

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


K
K 2012년 12월 21일
Thank you for your reply. Actualy I did the cumsum from this example: http://www.mathworks.co.uk/help/matlab/ref/histc.html
According to the bar graph, I need to find the y value when x=7000.

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by