简体   繁体   English

如果我不知道数组的具体大小,我如何在Matlab中制作一个图?

[英]How do I make a plot in Matlab if I do not know the specific size of the array?

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 所以我的问题是TubulinModel有一个随机数量的输出所以我一直在得到

??? ??? Error using ==> TubulinModel Too many output arguments. 使用==> TubulinModel时出错输出参数太多。

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

Is there A way to plot the data when I do not know the size of the array? 当我不知道数组的大小时,有没有一种绘制数据的方法?

The error you are getting ( Too many output arguments ) implies that the function TubulinModel doesn't actually return any outputs. 您获得的错误( Too many output arguments )意味着函数TubulinModel实际上不返回任何输出。 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. 函数TubulinModel应该传递至少一个输出参数供PLOT命令使用,它似乎没有做。 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. 如果这给你一个错误,那么这意味着你必须修改TubulinModel以便它返回你需要的数据,或者将这些数据放在一个全局变量中,你可以在函数外部访问并用于绘图。

Your loop doesn't appear to do anything different with the TublinModel function on subsequent iterations. 在后续迭代中,您的循环似乎与TublinModel函数没有任何不同。 Also, the plot function calls the function again, the same way the loops did. 此外,plot函数再次调用该函数,与循环相同。 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! 希望有所帮助!

When you call plot with two parameters, the first will be the x-axis data, and the second the y-axis data. 当您使用两个参数调用plot时,第一个将是x轴数据,第二个是y轴数据。 Is this what you intend? 这是你想要的吗? If you want TubulinModel() to be the y-axis data, you can do plot(TubulinModel()) . 如果你想将TubulinModel()作为y轴数据,你可以做plot(TubulinModel()) See help plot for more information. 有关更多信息,请参阅help plot

I don't understand why you call TubulinModel() ten times in the loop before calling it an eleventh time in plot ? 我不明白你为什么在循环中十次调用TubulinModel()之前在第一次调用plot

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM