Boolean Variables in Matlab

37 ビュー (過去 30 日間)
Akashdeep Saluja
Akashdeep Saluja 2013 年 7 月 1 日
Hi, I want to have a large 2D nxn array in which I want to store 0 or 1 at each cell, so basically a bit would do for one cell of a matrix. And the array I want to create have high dimensions so space is a constraint. So is there any thing which can provide bit access so that the whole program may run using decent memory.
Thanks
  2 件のコメント
Walter Roberson
Walter Roberson 2013 年 7 月 1 日
What operations do you need to perform on the array?
Akashdeep Saluja
Akashdeep Saluja 2013 年 7 月 1 日
@Walter: basically I want to use the matrix as a chromosome in Genetic Algorithm, if you are not familiar with Genetic Algorithms, I just need to swap some rows of a matrix with other matrix many times in the algorithm.

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

回答 (1 件)

Jonathan Sullivan
Jonathan Sullivan 2013 年 7 月 1 日
編集済み: Jonathan Sullivan 2013 年 7 月 1 日
No. MATLAB does not have any native bit sized data types. The best you are going to be able to do is to (without creating your own class) is use logicals, which esentially are bytes (8 bits). Also, do not use cell array if you are concerned about space. Each element in a cell array has a non-neglegable amount of overhead to define the size, shape, and type of the data it stores.
help logical
doc logical
  3 件のコメント
Akashdeep Saluja
Akashdeep Saluja 2013 年 7 月 1 日
Thanks, I haven't used sparse array, my data is not dense you can say it is sparse and about 80% of the elements in the matrix would be zero, but just want to make sure will it be suitable for use in genetic algorithms in which i need to swap rows of matrix A with rows of matrix B, also the matrix would be symmetric so I will be need to swap columns also. So basically the swap between the matrices would be like a '+' sign where horizontal bar represents swap of rows and vertical bar represents columns..
James Tursa
James Tursa 2013 年 7 月 1 日
編集済み: James Tursa 2013 年 7 月 1 日
FYI, doing anything that changes the non-zero locations of a sparse matrix will in all likelihood lead to copying the entire underlying dataset to new memory. I.e., each and every operation you do that changes the non-zero locations will cause an entire dataset copy to take place. This will drag your performance considerably depending on the sizes involved.

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

カテゴリ

Help Center および File ExchangePerformance and Memory についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by