如何从4D matlab矩阵中删除元素

时间:2012-07-30 22:41:56

标签: matlab matrix

您好我有以下4D矩阵

for idx_number_panels = 1:length(number_panels) % range of PV panel units examined

for number_turbines = 0:2 % range of wind turbine units examined

    for number_batteries = 1:10 % range of battery units examined


        for h=2:25 %# hours

            for d = 1:number_of_days %# which day

                n = h + 24*(d-1);
                % hourly_deficit_1(...,..., h, d)= Demand(n)-(PV_supply(n)... %


                hourly_total_RES(idx_number_panels,number_turbines + 1,number_batteries, h,d)

我想从上面的4D矩阵中每24行删除整行,从而调整矩阵的大小。这是可能的,如何做到这一点,因为文档似乎没有帮助

谢谢

1 个答案:

答案 0 :(得分:0)

  1. 创建要保留的所有行索引的向量
  2. 仅将那些行的hourly_total_RES编入索引并分配回hourly_total_RES。

    trashidx = 1:24:idx_number_panels;

    keepidx = setdiff(1:idx_number_panels,trashidx);

    hourly_total_RES = hourly_total_RES(keepidx,:,:,:);

  3. 而且我不知道为什么以上不是格式化代码....