Plot a huge data in Matlab

67 次查看(过去 30 天)
sally_wu
sally_wu 2015-10-14
评论: Umar 2024-7-28
I am trying to plot a cdf with the following data. I have a huge data with one column and total numbers are 116100 i.e. 116100x1 double. A minimum=0, maximum=1734719, average=1022, and standard deviation=16312. Every my attempt to plot the ecdf is crushed and shows just a straight line instead of showing a curve (cdf). I think Matlab cannot handle such big data.
  1 个评论
Umar
Umar 2024-7-28

Hi Sally,

Since I don't have the actual dataset, I will generate some random data that resembles the characteristics provided (116,100 data points, minimum=0, maximum=1,734,719, average=1022, standard deviation=16,312).

% Generate random data

data = 16312 * randn(116100, 1) + 1022;

Next, I will calculate the CDF values for the dataset and use the ecdf function in MATLAB to compute the empirical CDF.

[f, x] = ecdf(data);

Now, I can plot the CDF using the generated data and CDF values. language-matlab

figure;

plot(x, f, 'LineWidth', 2);

xlabel('Data Points');

ylabel('Cumulative Probability');

title('Cumulative Distribution Function (CDF) Plot');

grid on;

Please see the attached plot.

请先登录,再进行评论。

回答(1 个)

Kirby Fears
Kirby Fears 2015-10-14
Matlab can easily plot this data. Is each column of your 116100x4 double a separate variable that you want to plot?
Try plotting one column of Y values against whatever your X values are, e.g.
plot(X,Y(:,1));
Below is a simple example that plots a normal distribution with mu and sigma as you indicated.
X=(1:116100)';
Y=1022+16512*randn(size(X));
plot(X,Y);
This plot looks exactly as expected. Since there are so many X observations, the plot looks very compressed along the X axis. You could "zoom in" on a portion of the data to get a better view, as done below.
idx=1:100;
plot(X(idx),Y(idx));
Much more detail is visible when fewer points are observed. You could apply this approach to a 4-column Y matrix as well if you want to see all 4 variables at once on a subset of X values.
% to plot a subset of Y column 1
plot(X(idx),Y(idx,1));
% to plot a subset of all 4 variables
plot(X(idx),Y(idx,:));
You may also be interested in plotting every 100th observation to thin out the sample and make it more readable. To do this, assign idx = 1:100:length(X);
Hope this helps.
  3 个评论
sally_wu
sally_wu 2015-10-14
I have this 116100x1, and want to plot ecdf
Kirby Fears
Kirby Fears 2015-10-14
编辑:Kirby Fears 2015-10-14
The point of my answer is to demonstrate how to plot any vector of this size. Using the ecdf() output is no different. Here is an example:
X=(1:116100)';
Y=1022+16512*randn(size(X));
[a,b] = ecdf(Y);
plot(b,a);
Please give this a try and adapt it to work for your own code.
Hope this helps.

请先登录,再进行评论。

产品

Community Treasure Hunt

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

Start Hunting!

Translated by