Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

help with matlab char arrays

Status
Not open for further replies.

SnkMajin

Bioengineer
Nov 1, 2004
2
Hi

I'm new to matlab, and i'm having some trouble and hope that you can help.

I need to create a 100 row * 500 col array in which each element holds one of 4 letters (a,t,g,c - dna). I'n not sure how to do this, yet.

Will i need to create a for loop? and how can i fill an array in matlab with letters?

I'd really apprciate any help

Thanks for your time

SnkMajin
 
Replies continue below

Recommended for you

You don't need to but you can create a for loop. It won't affect your execution time.

Here is one solution to your problem
Code:
dna = ['a' 't' 'g' 'c'];
r = ceil(4*rand(100,500));  % generates random numbers 1-4 in a 100x500 matrix
m = dna(r);                 % matrix of random dna.
 
Hi JockeK,

Wow thanks, that works a treat! :D
I've been wracking my brain and had no joy! Had a different approach but your is way better.
I'm gonna have to manipulate this array now and think i have an idea.

Hope you dont mind me pestering you if icant get it to work.

Thanks again!
SnkMajin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor