views:

86

answers:

3

I have some code

function runTubulin()
  n = 10;
  for j = 1:n
      TubulinModel(); 
  end


plot(TubulinModel(), n);

So my problem is that TubulinModel has a random number of outputs So I keep getting

??? Error using ==> TubulinModel Too many output arguments.

Error in ==> runTubulin at 11 plot(TubulinModel(), n);

Is there A way to plot the data when I do not know the size of the array?

A: 

When you call plot with two parameters, the first will be the x-axis data, and the second the y-axis data. Is this what you intend? If you want TubulinModel() to be the y-axis data, you can do plot(TubulinModel()). See help plot for more information.

I don't understand why you call TubulinModel() ten times in the loop before calling it an eleventh time in plot?

mtrw
+1  A: 

Your loop doesn't appear to do anything different with the TublinModel function on subsequent iterations. Also, the plot function calls the function again, the same way the loops did. Assuming different data of random lengths is returned by each loop, you can store each set of data in an object array, then find out what parameters to use before plotting.

function runTubulin()

n = 10;
max_length = 0; max_pos = 0; max_neg = 0;
for j = 1:n
    data{j} = TublinModel();    % get your data, then characterize it
    if max(data(j)) > max_pos, max_pos = max(data(j)); end
    if max(-data(j)) > max_neg, max_neg = max(-data(j)); end
end

figure(1); % new axes
axis([0 10 -max_neg max_pos]); hold on; % scale the axis and freeze it
for j = 1:n
    plot(length(data(j)),data(j));
end

Hope that helps!

tyblu
+3  A: 

The error you are getting (Too many output arguments) implies that the function TubulinModel doesn't actually return any outputs. The function TubulinModel is expected to pass at least one output argument for the PLOT command to use, which it doesn't appear to be doing. You can check this by trying the following:

a = TubulinModel();  %# Place the output in a variable instead

If this gives you an error, then it means you will have to modify TubulinModel so that it returns the data you need, or places that data in a global variable that you can access outside of the function and use for the plot.

gnovice
Global variables? While that would work, I hate handing out foot-shooting guns... :)
MatlabDoug
@MatlabDoug: Normally I'd agreed, but since Ben hasn't given us much detail about the exact format of `TubulinModel` and how much of it he may or may not be able/allowed to modify, I figured I'd list all the possibilities he has.
gnovice