空行列の作成の利点

18 visualizaciones (últimos 30 días)
s
s el 1 de Dic. de 2020
Editada: Musashi Ito el 4 de Dic. de 2020
よく参考書などで、事前割り当てなどをmatlabでは推奨していますが、変数に空の行列を事前割り当てしている参考書をよく見るのですが、これは一体なんのために割り当てているのでしょうか。

Respuestas (1)

Musashi Ito
Musashi Ito el 1 de Dic. de 2020
Editada: Musashi Ito el 1 de Dic. de 2020
以下のドキュメンテーションのページが参考になるかと思いますが、いかがでしょうか。
  2 comentarios
s
s el 3 de Dic. de 2020
ご回答ありがとうございます。事前割り当てについてはforループにおいて高速する手段として有効だとはわかっているのですが、事前にサイズがわからない変数、例えばa=[]などと空の行列を割り振るメリットがわからないという趣旨でした。わかりにくくて申し訳ございません。
Musashi Ito
Musashi Ito el 4 de Dic. de 2020
Editada: Musashi Ito el 4 de Dic. de 2020
プログラムの書き方にもよるかと思いますが、もしかしたら for 文の中で、データの抽出や連結などがあり、事前にデータのサイズが分からない。さらに、データの抽出条件によっては空の場合もあり、事前に空のデータを定義しないとデータ型のエラーが発生するようなプログラムのため、かもしれません・・・

Iniciar sesión para comentar.

Categorías

Más información sobre Logical en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!