# Maximum PC

 It is currently Sun Apr 19, 2015 5:15 pm

 All times are UTC - 8 hours

 Page 1 of 1 [ 2 posts ]
 Print view Previous topic | Next topic
Author Message
 Post subject: Matlab helpPosted: Tue Jul 05, 2005 11:02 am
 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

 Post subject: Posted: Tue Jul 05, 2005 12:04 pm
 Bitchin' Fast 3D Z8000*

Joined: Tue Jun 29, 2004 11:32 pm
Posts: 2555
Location: Somewhere between compilation and linking
Top

 Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending
 Page 1 of 1 [ 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 forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot post attachments in this forum

Search for:
 Jump to:  Select a forum ------------------ Maximum FAQs    Forum Rules, Posting Guidelines & Announcements    The Good, The Bad & The Banned    FAQs Help/Do It Yourself    PC Building Lab    The Help Desk    PC Modding    Education & Certification Hardware    Nuts & Bolts    Portable Talk    Appraisals, Deals & Bargains (oh my!) OS/Software/Programming    Windows Parlor    Alt.OS.Abode    Games Arena    Programmers' Paradise Networking/Internet    Internet Truckstop    Network Nook In/Out    Magazine and Book Feedback    Forum & Website Feedback    Dog Pound Team Maximum PC Folding at Home    Team Maximum PC - Folding at Home - FIND CURES TO DISEASES    Team MPC - Folding Gauntlets