How should I plot the CDF for another parameter

1 vue (au cours des 30 derniers jours)
shufan Wang
shufan Wang le 9 Sep 2022
I have a waveform data that describes the variation of amplitude with height. I want to plot a CDF plot of the amplitude variation with height, but I have not found how it should be plotted(Just like the picture). I only found the way to plot the CDF plot of the amplitude itself.
My data is in the attachment, and code is here:
waveform=readtable(waveformLoc);
x=waveform.Elevation_m_;
y=waveform.Amplitude_DN_;
plot(x_flip,y_flip,'b'); %show the waveform
[f,x] = ecdf(y);
plot(x,f); %CDF about amplitude itself

Réponses (1)

Varun
Varun le 8 Sep 2023
Hi Shufan,
Looks like you want to plot CDF of amplitude variation with elevation. Currently you are able to plot CDF of the amplitude with amplitude itself.
Please refer the following code snippet to plot CDF of amplitude variation with elevation:
data = readtable('Data.csv');
amplitude = data{:, 2}; % Assuming the amplitude is in the second column
elevation = data{:, 3}; % Assuming the elevation is in the third column
% Sort the amplitude values based on elevation
[sortedElevation, sortIdx] = sort(elevation);
sortedAmplitude = amplitude(sortIdx);
% Calculate the empirical CDF using ecdf
[f, x] = ecdf(sortedAmplitude);
% Plot the CDF
plot(sortedElevation, f);
xlabel('Elevation (m)');
ylabel('Cumulative Probability');
title('CDF Plot: Amplitude Variation with Elevation');
Here is the breakdown of the code:
  1. The code sorts the elevation values in ascending order using the sort function and stores the sorted values in the variable sortedElevation.
  2. The sort function also returns the corresponding indices of the sorted values, which are stored in the variable sortIdx.
  3. The code rearranges the amplitude values based on the sorted elevation indices using indexing, resulting in the sorted amplitudes stored in the variable sortedAmplitude.
  4. The ecdf function is used to calculate the empirical cumulative distribution function (CDF) of the sorted amplitude values.
  5. The ecdf function returns two outputs: f represents the cumulative probabilities, and x represents the corresponding amplitude values.
  6. Finally, a plot is generated, showing the CDF values for amplitute plotted against the elevation values with appropriate axis labels and a title.
Hope this helps.

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by