简体   繁体   English

每次循环在Matlab中循环创建一个新的单元格数组

[英]create an new cell array everytime a loop cycles through in matlab

I am new to MatLab but I have some experience with C#. 我是MatLab的新手,但是我对C#有一定的经验。 I have a large dataset <169360x97> that I need to break up into 464 cell arrays. 我有一个大型数据集<169360x97>,需要将其分解为464个单元格阵列。 I currently have a loop that will cycle through the dataset and make a cell array, but I can not figure out how to have the loop create a new cell array every time instead of just rewriting over the same data. 我目前有一个循环,它将循环遍历数据集并创建一个单元格数组,但是我无法弄清楚如何让该循环每次都创建一个新的单元格数组,而不仅仅是重写相同的数据。 Here is the loop I have written. 这是我编写的循环。

    b=5476;
    e=5840;
    while(b<169360)
     dataset2cell(JeaAddressKwh(b:e,1:97));
     b=e+1;
     e=e+365;
    end

I have tried the following, but i get an error message every time: 我尝试了以下操作,但是每次都会收到错误消息:

   n=16;
   b=5476;
   e=5840;
   while(b<169360)
    n=dataset2cell(JeaAddressKwh(b:e,1:97));
    n+1;
    b=e+1;
    e=e+365;
   end

So basically what I am trying to get as an output is a different cell array called 16 through 464. I would appreciate any help. 因此,基本上,我想作为输出获得的是称为16到464的另一个单元格数组。我将不胜感激。 Thanks. 谢谢。

In the first loop you are not saving the cell array and in the second loop you over overwriting the previous cell array and trying to add 1 to it, without saving the result. 在第一个循环中,您没有保存单元格数组,在第二个循环中,您覆盖了先前的单元格数组并尝试向其添加1,而不保存结果。

Try something like this: 尝试这样的事情:

   n=cell(16,1);
   b=5476;
   e=5840;
   i = 1;
   while(b<169360)
       n{i}=dataset2cell(JeaAddressKwh(b:e,1:97));
       i = i+1;
       b=e+1;
       e=e+365;
   end

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM