Plot a huge data in Matlab

69 views (last 30 days)
sally_wu
sally_wu on 14 Oct 2015
Commented: Umar on 28 Jul 2024
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 Comment
Umar
Umar on 28 Jul 2024

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.

Sign in to comment.

Answers (1)

Kirby Fears
Kirby Fears on 14 Oct 2015
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 Comments
sally_wu
sally_wu on 14 Oct 2015
I have this 116100x1, and want to plot ecdf
Kirby Fears
Kirby Fears on 14 Oct 2015
Edited: Kirby Fears on 14 Oct 2015
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.

Sign in to comment.

Products

Community Treasure Hunt

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

Start Hunting!