布尔跟随指针和数字元素

发布于 2025-01-20 09:16:51 字数 847 浏览 1 评论 0原文

我正在尝试使用布尔标志来确定需要加载哪些数据。例如,我有 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 列的指令,我不想要

它如何生成我的布尔值?

I'm trying to use boolean flags to determine which data needs to be loaded. For example, I have 5 data sets and I ordered them by energy with a pointer which is in an array in MATLAB. I have to connect 2 data sets which have the following order: order =[5 2 3 4 1]
That means if I have to use 1 data set the boolean will be

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

If 2 data sets must be loaded:

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

I tried to use b=true(order(1,1:nbr_load)), but this results in

5×2 logical array
    
b =
1   1
1   1
1   1
1   1
1   1

it seeems the origin of the problem is this

order(1,1:nbr_load)

ans =

     5     2

It is an instruction to form 5 lines to 2 columns, which I do not want

How can I generate my booleans?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

擦肩而过的背影 2025-01-27 09:16:51

我将使用一个简单的循环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

I'd use a simple loop over order into a logical array b, using 1:ii to select the relevant elements from order:

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文