필터 지우기
필터 지우기

can i do this program in matlab

조회 수: 2 (최근 30일)
joy
joy 2012년 12월 14일
hello,
I have a note pad file of lots of bits means 1 & 0 like,1110001111000011111000000111000....Now I want take 8 bit from this bit pattern and store it to another notepad file in space separated like my 2nd notepad file should be like this..
11100011 11000011 11100000 ......like this a
I need this output in decimal is bin2dec be perfect.i need o/p like 23 45 56 in this manner
any idea plz share

채택된 답변

Matt Kindig
Matt Kindig 2012년 12월 14일
Hi joy,
Your question is a bit unclear. It sounds like you are trying to do two different things: 1) You want to write a new text file that inserts spaces between every set of 8 bits, and 2) You want to convert the binary strings into decimals.
First the former-- the easiest way to do this is just to read the text file into Matlab, arrange the matrix into groups of 8, and write a new file. Like this:
txt = fileread('/path/to/your/file.txt'); %read original file to string
n = 8*ceil(length(txt)/8); %number of characters to pad txt variable
txt(end:n)= ' '; %pad to set length to be a multiple of 8
Txt = reshape(txt', 8, [])'; %reshape
Txt(:,end+1)=' '; %add a space after each set of 8 characters
TT = reshape(Txt', 1, []); %convert back to a vector
%now write string to new file
fid = fopen('/path/to/new/file.txt', 'wt');
fprintf(fid, '%s', TT);
fclose(fid);
  댓글 수: 6
joy
joy 2012년 12월 15일
thank you,,,got ur logic
joy
joy 2012년 12월 15일
but sometime i am getting this error,what could be the reason?
??? Error using ==> bin2dec at 54 Binary string may consist only of characters 0 and 1
Error in ==> method_1_3D_2D_plot_stats_modified at 46 Dec = num2str(bin2dec(Txt)); %convert to decimal string

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

태그

아직 태그를 입력하지 않았습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by