Matlab 如何创建接受字符串的向量?

Matlab 如何创建接受字符串的向量?,matlab,Matlab,问题是,我想得到数学函数。在程序运行之前我不知道有多少 当它运行时,我要求输入一个n要接收的函数数,然后它开始从输入中保存它们 到目前为止,我有这个 function test() n = input('number of equations?'); v = [1:n] %in an ideal world, this ^ here would allow me to put a string in each position but % they are not the sam

问题是,我想得到数学函数。在程序运行之前我不知道有多少

当它运行时,我要求输入一个
n
要接收的函数数,然后它开始从输入中保存它们

到目前为止,我有这个

function test()  
n = input('number of equations?');  
v = [1:n]  
%in an ideal world, this ^ here would allow me to put a string in each position but  
% they are not the same type and I understand that.. but how can I build a vector for saving my                functions  
%I want a vector where I can put strings in each position that is what I need   
for i=1:n  
x = input('what is the function?','s');  
v(i)=x  
end  
v   
%this would be my vector already changed with a function in each position.  
end  

如果要存储不同长度的字符串,请使用单元格数组:

v = cell(1,n);
for i=1:n   
    v{i} = input('what is the function?','s'); #% note the curly braces
end  
要使用这些函数,请使用:

fh
现在是一个单元格数组,包含用户输入字符串定义的函数句柄

for i=1:n
    fh{i} = str2func(v{i});
end