小编Max*_*ell的帖子

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
Run Code Online (Sandbox Code Playgroud)

我希望在任何地方将读取[n]切换到实际值n,这样我就可以使用它将数据添加到格式的九个不同变量中msgLength#.我试过搜索教程,但没有看到任何关于这个主题的内容.

variables matlab loops naming-conventions

3
推荐指数
1
解决办法
4773
查看次数

Matlab:在我的代码中删除"Switch/Case"

您不需要阅读所有这些代码,但我将其发布以供参考.我需要将以下代码段从0-8更改为n.在案例之间唯一改变的是z的范围和变量名称(msgLength0,msgLength1,msgLength2等)我正在努力.我已经尝试将变量msgLength#放入一个数组中,但是如果没有"count"变量则无法将数据分配给正确的行.

如何在个别情况下摆脱这种"切换"并使用变量而不是单独定义msgLength#?

for these folders
   for these files
        countmsgLength0= 1;
        countmsgLength1= 1;
        countmsgLength2= 1;
        countmsgLength3= 1;
        countmsgLength4= 1;
        countmsgLength5= 1;
        countmsgLength6= 1;
        countmsgLength7= 1;
        countmsgLength8= 1;
        for x= 1:length(firstinSeq)
        for y= 1:length(littledataPassed)
          if firstinSeq(x,1)== littledataPassed(y,1) && firstinSeq(x,2)== littledataPassed(y,2)
            switch firstinSeq(x,3)
            case 0
                indexStop = find(firstinSeq(x,4) ~= littledataPassed(y:length(littledataPassed),4), 1, 'first'); 
                indexProcess = find((littledataPassed(y:y+indexStop-1,6) == 1 & ... 
                   littledataPassed(y:y+indexStop-1,2) == firstinSeq(x,2) & ... 
                   littledataPassed(y:y+indexStop-1,5) == 0),1,'first'); 
                if isempty(indexProcess)
                   msgLength0(countmsgLength0,:)= [firstinSeq(x,:) [0 0 0 0 0 0]];                   
                else msgLength0(countmsgLength0,:)= [firstinSeq(x,:) littledataPassed(y+indexProcess-1,:)];
                end
                countmsgLength0= …
Run Code Online (Sandbox Code Playgroud)

matlab

0
推荐指数
1
解决办法
552
查看次数

标签 统计

matlab ×2

loops ×1

naming-conventions ×1

variables ×1