0

In Matlab does both the commands use same size of memory and is their time complexity same too?

B = zeros(5)
B = ones(5)
NobinPegasus
  • 545
  • 2
  • 16
  • 1
    You can test it yourself by timing the functions. `zeros` tends to be faster, because the OS can return zero-initialized memory, but not one-initialized memory. This means that MATLAB must fill the `ones` array with values, but not the `zeros` array. – Cris Luengo Jun 04 '21 at 07:17
  • [This answer](https://stackoverflow.com/a/48724131/3978545) addresses timing for many different initialisation methods – Wolfie Jun 04 '21 at 07:27

0 Answers0