How should I plot the CDF for another parameter

조회 수: 1 (최근 30일)
shufan Wang
shufan Wang 2022년 9월 9일
답변: Varun 2023년 9월 8일
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

답변 (1개)

Varun
Varun 2023년 9월 8일
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.

카테고리

Help CenterFile Exchange에서 Matched Filter and Ambiguity Function에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by