首页 > 解决方案 > 我可以将包含多个变量的函数存储在 cellfun 中,仍然可以单独使用吗?

问题描述

我是matlab的新手,它是否能够存储包括多个变量的函数仍然可以使用?是否能够得到与下面相同的结果?

%example
f=sin(x*t+theta);   % function I used
x=[1 2 3 4 5 6 7 8 9 10];   % spactial distribution  % will remain unchange in for loop
t=[1 2 3 4 5];     % time
theta=[1 2 3 4 5];     % phase change by time (will be same length as time)
  first, I would like to do something to this function to made it :
F=[ sin(x*t+1) sin(x*t+2) sin(x*t+3) sin(x*t+4) sin(x*t+5)];

所以我可以调用函数,例如: F{1}=sin(x*t+1) 接下来,F中的函数需要按时间一起移动:

for b=1:length(theta)     % F{1},F{2},F{3},F{4},F{5}
    for a=1:length(t)    % time change
        A=F{b}(a);      % (a) is suppose to be the time change, but I don't know how to do with it
    end
end

波函数最后会在我的代码中计时一个阶跃函数,所以我不能改变我的代码的顺序,它需要像这样一步一步地进行。t和theta的长度会大于1000,所以无法一一键入函数。

标签: matlab

解决方案


推荐阅读