Declaring types in MATLAB

2 ビュー (過去 30 日間)
Fernando Riveiro Formoso
Fernando Riveiro Formoso 2020 年 5 月 16 日
コメント済み: Walter Roberson 2020 年 5 月 18 日
When preallocating, is it possible to declare types?
If so, how can I do it? Is it worthy in terms of efficiency?

採用された回答

Stephen23
Stephen23 2020 年 5 月 16 日
編集済み: Stephen23 2020 年 5 月 16 日
"When preallocating, is it possible to declare types? "
When preallocating you can select any suitable data type, e.g.:
A = zeros(2,3, 'uint8')
Read the zeros, ones, nan documentation to know more.
"Is it worthy in terms of efficiency?"
In most cases preallocation is more efficient than not preallocating.
  4 件のコメント
Fernando Riveiro Formoso
Fernando Riveiro Formoso 2020 年 5 月 17 日
Since preallocating improves efficiency before a for loop that fills a matrix with numbers, I was just wondering whether declaring the type of the numbers we are going to fill the matrix with could also improve efficiency... but seems from your answer it is not the case in general. Thank you very much for your answers!
Walter Roberson
Walter Roberson 2020 年 5 月 18 日
datatype can make a big difference, but which is faster can depend upon the processor. There are a range of processors for which single is always faster than double, but then there can be oddities like double multiplication being faster.
http://nicolas.limare.net/pro/notes/2014/12/12_arit_speed/

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

タグ

製品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by