![]() |
MATLAB:如何在另一个变量名称中使用变量值?
我想知道这是否可能。我的代码如下所示:
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#我尝试搜索教程,但没有找到关于该主题的任何内容。 [B]回答:[/B] 与创建一堆名为a1 , a2 , a3等的变量相比,使用数组或[URL="http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_prog/br04bw6-98.html"]单元格数组[/URL]存储数据几乎总是更好。例如,您可以将msgLength初始化为具有n元素的单元格数组: msgLength = cell(1,n); 您可以使用花括号访问msgLength单元格: msgLength{n} = ... %# Assign something to cell n 您的变量countmsgLength只能是一个常规数字数组,因为它似乎只存储n值。您只需要将方括号更改为括号(即[n]至(n) )。 [B]但是[/B] ,如果您[I]确实[/I]要创建n单独的变量,则可能最终会使用[URL="http://www.mathworks.com/access/helpdesk/help/techdoc/ref/eval.html"]EVAL[/URL]函数。 [URL="https://stackoverflow.com/questions/2809635/how-to-concatenate-a-number-to-a-variable-name-in-matlab"]这个问题[/URL]和[URL="https://stackoverflow.com/questions/3143959/using-matlab-loop-funtion-to-name-calculate-variables"]这个问题[/URL]展示了一些如何使用另一个变量的值创建变量名称的示例。 [url=https://stackoverflow.com/questions/3346178]更多&回答...[/url] |
所有时间均为北京时间。现在的时间是 10:57。 |
Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.