Quantcast

Maximum PC

It is currently Tue Sep 16, 2014 9:52 pm

All times are UTC - 8 hours




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: Matlab help
PostPosted: Tue Jul 05, 2005 11:02 am 
8086
8086

Joined: Tue Jul 05, 2005 10:53 am
Posts: 1
If any of you are familiar with matlab, even basic knowledge, your help would be much appreciated because of my lack of understanding/familiarity with matlab...

What I need to do is make an m-file that can extract input from a text file, change it into 16-bit binary while being precise as possible, and store that new 16-bit binary string onto another text file. The text file that I need to extract data from comprises of negatives and decimals ie. -0.0015, 0.00654. The function used to change integers to binary is "dec2bin" and only works with non-negative integers so to solve this problem, I've added and multiplied to the string to convert them to integers. I've heard that 2's complement and LSB could be used to solve this problem but I am not familiar with either. Any explanation would be useful. Thank you in advance.

Here is what I have so far:

clear all
datastr=textread(uigetfile('*.txt','Choose Text File')); %select txt file
user_entry=input('Which column would you like to extract data from? ') %select column of data
x=datastr(:,user_entry); %extracts selected column of data

%if lowest # in string is negative, adds inverse negative # to string so
%that string becomes positive
if min(x)<=0
x_1=(x-min(x))+0.1
else
x_1=x
end

%finds value to multiply by x_1 to get the highest number < 2^16
if 6.5536>=max(x_1)>0.65536
mult=10000;
else
end
if 0.65536>=max(x_1)>0.065536
mult=100000;
else
end
if 0.0065536>max(x_1)>=0.00065536
mult=1000000;
else
end
if 0.00065536>max(x_1)>=0.000065536
mult=10000000;
else
end
if 0.000065536>max(x_1)>=0.0000065536
mult=100000000;
else
end

multnum=mult*x_1 %multiplies string by multiplier found previously
roundnum=round(multnum) %rounds multnum to nearest whole number
b_16=dec2bin(roundnum,16) %converts roundnum to binary, 16-bits


Top
  Profile  
 
 Post subject:
PostPosted: Tue Jul 05, 2005 12:04 pm 
Bitchin' Fast 3D Z8000*
Bitchin' Fast 3D Z8000*
User avatar

Joined: Tue Jun 29, 2004 11:32 pm
Posts: 2555
Location: Somewhere between compilation and linking
http://www.duke.edu/~twf/cps104/twoscomp.html


Top
  Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 8 hours


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group