小编sum*_*dds的帖子

结构的Matlab数组:快速赋值

有没有办法"vector"分配一个struct数组.

目前我可以

edges(1000000) = struct('weight',1.0); //This really does not assign the value, I checked on 2009A.
for i=1:1000000; edges(i).weight=1.0; end; 
Run Code Online (Sandbox Code Playgroud)

但这很慢,我想做更多的事情

edges(:).weight=[rand(1000000,1)]; //with or without the square brackets. 
Run Code Online (Sandbox Code Playgroud)

任何想法/建议来矢量化这个任务,以便它会更快.

提前致谢.

arrays matlab struct vectorization variable-assignment

11
推荐指数
3
解决办法
2万
查看次数

各种protobuf实现之间的差异

每种实现的权衡,优缺点是什么?他们有什么不同吗?我想要实现的是将一个盒子的矢量存储到一个protobuf中.

Impl 1:

package foo;

message Boxes
{ 
  message Box 
  { required int32 w = 1;
    required int32 h = 2;
  }

  repeated Box boxes = 1; 
}
Run Code Online (Sandbox Code Playgroud)

Impl 2:

package foo;

message Box 
{ required int32 w = 1;
  required int32 h = 2;
}

message Boxes 
{ repeated Box boxes = 1; 
}
Run Code Online (Sandbox Code Playgroud)

Impl 3:将这些消息的多个流式传输到同一个文件中.

package foo;

message Box 
{ required int32 w = 1;
  required int32 h = 2;
}
Run Code Online (Sandbox Code Playgroud)

protocol-buffers

3
推荐指数
2
解决办法
1168
查看次数