指针和数字元素后面的布尔值



我正在尝试使用布尔标志来确定需要加载哪些数据。例如,我有5个数据集,我用MATLAB中的数组中的指针按能量对它们进行排序。我必须连接两个数据集,它们的顺序如下:order =[5 2 3 4 1]这意味着如果我必须使用1个数据集,布尔值将是

b= [ 0 0 0 0 1] % the fifth data set will de loaded 
Power_load_1 = calculalation_X *b=0
to
Power_load_4 = calculalation_X *b=0
Power_load_5 = calculalation_X *b= a result

如果必须加载2个数据集:

b= [ 0 1 0 0 1]
Power_load_1 = calculalation_X *b=0
Power_load_2 = calculalation_X *b= a result
Power_load_3 and 4 = calculalation_X *b=0
Power_load_5 = calculalation_X *b= a result

我尝试使用b=true(order(1,1:nbr_load)),但这导致

5×2 logical array

b =
1   1
1   1
1   1
1   1
1   1

看来问题的根源是这个

order(1,1:nbr_load)
ans =
5     2

这是一条形成5行到2列的指令,我不想要

如何生成布尔值?

我会使用一个简单的循环,通过order进入逻辑数组b,使用1:iiorder:中选择相关元素

order =[5 2 3 4 1];
b = zeros(numel(order),max(order), 'logical');  % Initliase output
for ii = 1:numel(order)
b(ii,order(1:ii)) = 1;
end
b
b =
0     0     0     0     1
0     1     0     0     1
0     1     1     0     1
0     1     1     1     1
1     1     1     1     1

最新更新