Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在matlab中将向量转换为单元数组?_Matlab_Data Structures - Fatal编程技术网

如何在matlab中将向量转换为单元数组?

如何在matlab中将向量转换为单元数组?,matlab,data-structures,Matlab,Data Structures,我有两段代码,如下所示: nodes = randsample ( n_nodes, round(j*n_nodes) )-1; nodes_seqs = arrayfun (@transfer, nodes, 'UniformOutput', false ); nodes = num2str(nodes); nodes = cellstr(nodes); file_n = strcat('fasta','_','myfilename' ); % file name fas

我有两段代码,如下所示:

nodes = randsample ( n_nodes, round(j*n_nodes) )-1;      
nodes_seqs = arrayfun (@transfer, nodes, 'UniformOutput', false );

nodes = num2str(nodes);

nodes = cellstr(nodes);
file_n = strcat('fasta','_','myfilename' );  % file  name

fastawrite(strcat( file_n, '.fas' ), nodes, nodes_seqs);
另一个是:

nodes = 0 : n_nodes-1;

nodes_seqs = arrayfun (@transfer, nodes, 'UniformOutput', false );

nodes = num2str(nodes);

nodes = cellstr(nodes);
file_n = strcat('myfilename' );  % file  name

fastawrite(strcat( file_n, '.fas' ), nodes, nodes_seqs);

第一个按预期运行。但是,第二个错误出现了。在检查变量之后,我得到了第二个变量,节点是一个1乘1单元数组。我很困惑。它怎么会对第一个有效,而不是第二个?非常感谢您的时间和关注

在第二种情况下,因为节点是需要使用的单元数组

nodes=cell2mat(nodes)
而不是
num2str
,因为此时的数据类型为cell,而不是num

下面是该函数的链接


其他选项是函数
cell2struct()
cell2table()

。这里的主要原因是:在第一段中,randsample返回一个列向量,而在第二段中,节点被初始化为行向量。在添加转置后,它可以工作

谢谢你的关注。我终于找到了原因。