-1

I am trying to plot a CDF for my data, but I get the following error message:

Error using cdf (line 69) Not enough input arguments

My code:

 data =cell(1,5);
 for j=1:length(container)-7
        data{j} = some_values;
 cdfplot(data)

So data is a 1x5 cell while inside of it, the values are the following 1x14600double, 1x260double, 1x2222double, 1x3000double, 1x72double

I am expecting a separate line for each of the double arrays i.e. my cdf figure to have 5 lines. But, the error message confuses me, since I definitely have passed data. Any ideas?

Edited: ok, I have misswritten instead of cdfplot(), I had cdf()... the problem stays the same

SecretAgentMan
  • 2,856
  • 7
  • 21
  • 41
CroatiaHR
  • 615
  • 6
  • 24
  • 2
    No real clue what you are trying to do, is it possible that you mixed up 'cdf' and 'cdfplot'? – Daniel Aug 05 '19 at 21:30
  • I cannot reproduce this. Random data: `A = {rand(1,14600) rand(1,260) rand(1,2222) rand(1,3000) rand(1,72)};` Bookkeeping: `szA = size(A);` Testing [`cdfplot`](https://www.mathworks.com/help/stats/cdfplot.html): `for k = 1:szA(2), subplot(5,1,k), cdfplot(A{k}), end` works fine in MATLAB R2018b. – SecretAgentMan Aug 06 '19 at 16:02

2 Answers2

1

The problem was the lack of knowledge on how cells and figures work.

figure;
hold on;
cellfun(@cdfplot,data);

This code did the job :)

CroatiaHR
  • 615
  • 6
  • 24
0

In addition to the OP's answer using cellfun, you can also solve this by adjusting how you access the cell array.

Key Idea: Access A with A{} versus A()

% MATLAB R2018b
% Sample data
A = {rand(1,14600) rand(1,260) rand(1,2222) rand(1,3000) rand(1,72)};

Notice that A(1) returns

ans = 1×1 cell array {1×14600 double}

while A{1} returns the full 1x14600 double array (extracts it completely from the cell array).

% Example usage
szA = size(A);
for k = 1:szA(2)
    subplot(5,1,k)
    cdfplot(A{k})
end

From this example you can see cdfplot works fine.

SecretAgentMan
  • 2,856
  • 7
  • 21
  • 41