简体   繁体   English

如何在Matlab中返回列表?

[英]How to return a list in matlab?

Let me first start by saying that I am not good at programming yet. 首先,我要说我还不擅长编程。 I have the following exercise: 我有以下练习:

Define a function which iterates the Ricker model a total of 600 times for a particular value of a . 限定该迭代的Ricker子模型总计600次特定值的函数。 The arguments of the function should be the parameter a and the initial condition x0 . 该函数的参数应为参数a和初始条件x0 Your procedure should return a list (for example, mylist ) that contains the coordinates for the points that will appear in the Feigenbaum diagram. 您的过程应返回一个列表(例如, mylist ),其中包含将出现在Feigenbaum图中的点的坐标。 Note that you do not create coordinates for the first 500 iterates, only for last 100 iterates. 请注意,您不会为前500个迭代创建坐标,而只会为后100个迭代创建坐标。 Hint: Each coordinate in the list should be of the form [a,iter] not [i,iter] . 提示:列表中的每个坐标应为[a,iter]而不是[i,iter] Make sure your program returns the values in the list. 确保您的程序返回列表中的值。

Here's what I have so far: 这是我到目前为止的内容:

function y = ex824(a)
    RM      = @(x) a*x.*exp(-x);
    prompt  = 'Specify an initial condition: ';
    result  = input(prompt);
    iter(1) = result;

% collecting list of x-coordinates
    for i = 1:601,   
        X(i) = i - 1;
    end

% collecting list of y-coordinates
    for i = 1:600,
        Y(i+1)      = RM(iter(i));
        iter(i+1)   = Y(i+1);
    end

    y = plot(X, Y, '*');
end 

I have a couple of matlab programming books, but I've been reading for days and have yet to come across something that shows me how to return a list. 我有几本matlab编程书籍,但是我已经阅读了好几天,但还没有看到向我展示如何返回列表的内容。 Can anyone help? 有人可以帮忙吗?

All you need to do is to generate a list and assign this to your return variable. 您需要做的就是生成一个列表,并将其分配给您的返回变量。

function a = testReturnList(size)
  a = ones(size, 1);
  %a = [1;2;3];
end

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

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