How to extract data from cdfplot()
조회 수: 6 (최근 30일)
이전 댓글 표시
Hello, allow me inqure something that might be simple but is proving to be a challenge to me. I have this code attached. I would like to extract data from the cdfplot() but I keeop getting errors (error attached below) even after reoving the inf at the end. What can be the problem and how can I avoid it?
A =10*rand(100000,1);
figure()
cdfplot(A)
H = get(gca, 'Children');
x = get(H, 'XData');
y = get(H, 'YData');
xr = 1.24
yr = interp1(x, y, xr)
Error using griddedInterpolant
The coordinates of the input points must be finite values; Inf and NaN are not permitted.
Error in interp1 (line 151)
F = griddedInterpolant(X,V,method);
Error in Epr7errorfunc (line 10)
yr = interp1(x, y, xr)
댓글 수: 0
채택된 답변
Drishti
2024년 10월 9일
Hi Okoth,
While reproducing the provided code on my end, I encountered the same issue ‘Coordinates of input point must be finite’.
This can be resolved by removing the ‘Inf’ and ‘NaN’ values from the input points. You can refer to the code snippet below to understand how to remove ‘Inf’ and ‘NaN’ values.
% Remove Inf and NaN values
finiteMask = isfinite(x) & isfinite(y);
x = x(finiteMask);
y = y(finiteMask);
Additionally, make sure that the values are unique by following the implementation outlined below to maintain the uniqueness property.
% Ensure x values are unique by averaging y values for duplicate x values
[xUnique, ~, ic] = unique(x);
yUnique = accumarray(ic, y, [], @mean);
xr = 1.24;
yr = interp1(xUnique, yUnique, xr);
For more information, refer to the MATLAB Documentation of ‘cdfplot’ and ‘accumarray’ function.
I hope this helps in getting started.
댓글 수: 0
추가 답변 (1개)
Shreeya
2024년 10월 8일
Hello
The error suggests that either zeros/NaN values are being generated in the code due to an arithmetic operation. Applying appropriate conditions to avoid such data points should help mitigate the issue.
Refer to the below MATLAB Answer to understand all the possible reasons resulting in NaN values to help avoid them:
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!