Convert a multidimensional array into respective single array

7 ビュー (過去 30 日間)
Willam Willam
Willam Willam 2012 年 12 月 29 日
Hi. I want ask how I need to convert the data that I read from text file and put it in the single the form of 8 bits per each array. Thanks for help. Appreciate.
  4 件のコメント
Walter Roberson
Walter Roberson 2012 年 12 月 30 日
fread() is for binary files, not for converting text.
Willam Willam
Willam Willam 2012 年 12 月 30 日
From Image Analyst comment, I had use importdata() function and manage get my data in the form of A=[50 20]. But how I need to convert it into A=[11111111 11111111] and separate it into two arrays like A1=[11111111] A2=[11111111].

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

回答 (2 件)

Image Analyst
Image Analyst 2012 年 12 月 29 日
Is this what you mean:
array8bit = uint8(doubleArray);

Walter Roberson
Walter Roberson 2012 年 12 月 30 日
Putting your data into different arrays is not advised. Please read http://matlab.wikia.com/wiki/FAQ#How_can_I_create_variables_A1.2C_A2.2C....2CA10_in_a_loop.3F
To convert your values, use
bin2dec(A,8)
This will return a character array, one row for each input value, with each character being '0' or '1'. These will not be the numbers 0 and 1. If you want the numbers 0 and 1 instead of the characters '0' and '1', then use
bin2dec(A,8) - '0'
The result would be a number of rows, each 8 columns wide, with one row per input number.
If you were hoping that (for example) the input value 5 would convert to the decimal number 00000101, then although the conversion to decimal-coded-binary could be done, keep in mind that decimal values automatically drop leading 0's on output, so such an entry would print out as 101 rather than 00000101.
  27 件のコメント
Willam Willam
Willam Willam 2013 年 1 月 1 日
Ok. I will try it when I'm free. Because prepare for final exam. Thanks ya Sir Walter
Willam Willam
Willam Willam 2013 年 1 月 9 日
Sir walter, i tested already. It works but only for 1st array only. How to make it all arrays are recorded through this code? Thanks

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

カテゴリ

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

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by