我想知道这是否可能。我的代码如下所示:
indexStop = find(firstinSeq(x,4) ~= ... littledataPassed(y:length(littledataPassed),4), 1, 'first'); for z= 0:(n-1) indexProcess = find((littledataPassed(y:y+indexStop-1,6) == 1 & ... littledataPassed(y:y+indexStop-1,2) == firstinSeq(x,2) & ... littledataPassed(y:y+indexStop-1,5) == z), 1, 'first'); if isempty(indexProcess) msgLength[n](countmsgLength[n],:)= [firstinSeq(x,:) [0 0 0 0 0 0]]; else msgLength[n](countmsgLength[n],:)= [firstinSeq(x,:) ... littledataPassed(y+indexProcess-1,:)]; end countmsgLength[n]= countmsgLength[n] + 1; end 我希望能有无处不在读取[n]切换到的实际值n ,这样我可以使用它来格式的数据添加到九个不同的变量msgLength#我尝试搜索教程,但没有找到关于该主题的任何内容。
回答:
与创建一堆名为a1 , a2 , a3等的变量相比,使用数组或
单元格数组存储数据几乎总是更好。例如,您可以将msgLength初始化为具有n元素的单元格数组:
msgLength = cell(1,n); 您可以使用花括号访问msgLength单元格:
msgLength{n} = ... %# Assign something to cell n 您的变量countmsgLength只能是一个常规数字数组,因为它似乎只存储n值。您只需要将方括号更改为括号(即[n]至(n) )。
但是 ,如果您
确实要创建n单独的变量,则可能最终会使用
EVAL函数。
这个问题和
这个问题展示了一些如何使用另一个变量的值创建变量名称的示例。
更多&回答...