在Matlab中预先分配数组大小

时间:2015-12-14 04:20:50

标签: matlab memory-management

动态预分配数组变量大小的有效方法是什么,它似乎在Matlab的每次循环迭代中改变了它的大小?可以使用zeros()矩阵对其进行初始化,但有时候非常棘手(例如:确定上限和下限)。

1 个答案:

答案 0 :(得分:1)

这是我用于动态大小的2D数组的解决方案。假设我的数组的最大限制是2000x2000,那么我只是预先分配1-D矢量模拟的零(一个2000 ^ 2x1矢量)并在代码结束后摆脱零(或者只是在数据发生时忽略它们)如果需要,在代码结束后,一个直方图)和C:/Ruby200/lib/ruby/gems/2.0.0/gems/activerecord-4.2.3/lib/active_record/dynamic_matchers.rb:26:in `method_missing': undefined method `partia iveRecord::Base:Class (NoMethodError) from C:/Users/ryzal_000/Sites/dotforge/config/environment.rb:7:in `<top (required)>' from C:/Ruby200/lib/ruby/gems/2.0.0/gems/activesupport-4.2.3/lib/active_support/dependencies.rb:274:in `require' from C:/Ruby200/lib/ruby/gems/2.0.0/gems/activesupport-4.2.3/lib/active_support/dependencies.rb:274:in `block in require' from C:/Ruby200/lib/ruby/gems/2.0.0/gems/activesupport-4.2.3/lib/active_support/dependencies.rb:240:in `load_dependency' from C:/Ruby200/lib/ruby/gems/2.0.0/gems/activesupport-4.2.3/lib/active_support/dependencies.rb:274:in `require' from C:/Users/ryzal_000/Sites/dotforge/config.ru:3:in `block in <main>' from C:/Ruby200/lib/ruby/gems/2.0.0/gems/rack-1.6.4/lib/rack/builder.rb:55:in `instance_eval' from C:/Ruby200/lib/ruby/gems/2.0.0/gems/rack-1.6.4/lib/rack/builder.rb:55:in `initialize' from C:/Users/ryzal_000/Sites/dotforge/config.ru:in `new' from C:/Users/ryzal_000/Sites/dotforge/config.ru:in `<main>' from C:/Ruby200/lib/ruby/gems/2.0.0/gems/rack-1.6.4/lib/rack/builder.rb:49:in `eval' from C:/Ruby200/lib/ruby/gems/2.0.0/gems/rack-1.6.4/lib/rack/builder.rb:49:in `new_from_string' from C:/Ruby200/lib/ruby/gems/2.0.0/gems/rack-1.6.4/lib/rack/builder.rb:40:in `parse_file' from C:/Ruby200/lib/ruby/gems/2.0.0/gems/rack-1.6.4/lib/rack/server.rb:299:in `build_app_and_options_from_config' from C:/Ruby200/lib/ruby/gems/2.0.0/gems/rack-1.6.4/lib/rack/server.rb:208:in `app' from C:/Ruby200/lib/ruby/gems/2.0.0/gems/railties-4.2.3/lib/rails/commands/server.rb:61:in `app' from C:/Ruby200/lib/ruby/gems/2.0.0/gems/rack-1.6.4/lib/rack/server.rb:336:in `wrapped_app' from C:/Ruby200/lib/ruby/gems/2.0.0/gems/railties-4.2.3/lib/rails/commands/server.rb:139:in `log_to_stdout' from C:/Ruby200/lib/ruby/gems/2.0.0/gems/railties-4.2.3/lib/rails/commands/server.rb:78:in `start' from C:/Ruby200/lib/ruby/gems/2.0.0/gems/railties-4.2.3/lib/rails/commands/commands_tasks.rb:80:in `block in server' from C:/Ruby200/lib/ruby/gems/2.0.0/gems/railties-4.2.3/lib/rails/commands/commands_tasks.rb:75:in `tap' from C:/Ruby200/lib/ruby/gems/2.0.0/gems/railties-4.2.3/lib/rails/commands/commands_tasks.rb:75:in `server' from C:/Ruby200/lib/ruby/gems/2.0.0/gems/railties-4.2.3/lib/rails/commands/commands_tasks.rb:39:in `run_command!' from C:/Ruby200/lib/ruby/gems/2.0.0/gems/railties-4.2.3/lib/rails/commands.rb:17:in `<top (required)>' from bin/rails:4:in `require' from bin/rails:4:in `<main>' ......

例如:

reshape