Name: Anonymous 2010-11-03 19:53
Oi can someone help me with this plotting a double helix shit with matlab?'
It's primarily a tracing problem, just need to fix some errors, otherwise nearly all of the code is already there.
function plotDNA(name)
% Read the file and extract data about the rows and columns
[num txt raw] = xlsread(name);
[row col] = size(raw);
% Find the number of rows that have RNA strands (not headers)
rna_length = row;
% If each link occurs every pi/4 radians, find how many complete
% revolutions will be made in order to generate the polymer spirals
th = linspace(0,(2*pi*(rna_length/8))-(pi/4));
% Make sure that x and y are chosen so that they are centered around
% the origin (0,0) and the radius is 0.5
x = cos(th)/2;
y = sin(th)/2;
% Plot the 1st polymer "slinky"
plot3(x,y,th,'b');
hold on
% Plot the 2nd polymer "slinky", starting at the opposite x and y
% coordinate from which the 1st polymer began
plot3(-x,-y,th, 'b');
% Find the angle at which each rna pair should begin and place the
% corresponding starting positions in a vector
pairs = (pi/4)*(1:rna_length);
% Begin the first plot at pi/4. Add pi/4 to p after each repetition
p = pi/4;
% Since first row is the header, the base pairs begin on the 2nd row, 1st
% column of raw.
for i = 2:row
% Make sure that the corresponding pairs are chosen so they stem from the
% (0,0) with the appropriate rotation. c corresponds to the x-coordinate,
% and d corresponds to the y-coordinate.
c = 0.5*cos(pairs(i));
d = 0.5*sin(pairs(i));
% Plot DNA lines with the correct corresponding colors
switch raw{i,1}
case 'Adenine'
plot3([c 0],[d 0],[p p],'g')
plot3([0 c],[0 -d],[p p],'r')
case 'Uracil'
plot3([c 0],[d 0],[p p],'r')
plot3([0 -c],[0 -d],[p p],'g')
case 'Cytosine'
plot3([c 0],[d 0],[p p],'y')
plot3([0 -c],[0 -d],[p p],'m')
case 'Guanine'
plot3([c 0],[d 0],[p p],'m')
plot3([0 -c],[0 -d],[p p],'y')
end
p = pi/4 + p;
end
% =====================================================================
%Do not change the lines below! They are correct!
view(0,0)
axis([-2 2 -2 2 -1 rna_length])
It's primarily a tracing problem, just need to fix some errors, otherwise nearly all of the code is already there.
function plotDNA(name)
% Read the file and extract data about the rows and columns
[num txt raw] = xlsread(name);
[row col] = size(raw);
% Find the number of rows that have RNA strands (not headers)
rna_length = row;
% If each link occurs every pi/4 radians, find how many complete
% revolutions will be made in order to generate the polymer spirals
th = linspace(0,(2*pi*(rna_length/8))-(pi/4));
% Make sure that x and y are chosen so that they are centered around
% the origin (0,0) and the radius is 0.5
x = cos(th)/2;
y = sin(th)/2;
% Plot the 1st polymer "slinky"
plot3(x,y,th,'b');
hold on
% Plot the 2nd polymer "slinky", starting at the opposite x and y
% coordinate from which the 1st polymer began
plot3(-x,-y,th, 'b');
% Find the angle at which each rna pair should begin and place the
% corresponding starting positions in a vector
pairs = (pi/4)*(1:rna_length);
% Begin the first plot at pi/4. Add pi/4 to p after each repetition
p = pi/4;
% Since first row is the header, the base pairs begin on the 2nd row, 1st
% column of raw.
for i = 2:row
% Make sure that the corresponding pairs are chosen so they stem from the
% (0,0) with the appropriate rotation. c corresponds to the x-coordinate,
% and d corresponds to the y-coordinate.
c = 0.5*cos(pairs(i));
d = 0.5*sin(pairs(i));
% Plot DNA lines with the correct corresponding colors
switch raw{i,1}
case 'Adenine'
plot3([c 0],[d 0],[p p],'g')
plot3([0 c],[0 -d],[p p],'r')
case 'Uracil'
plot3([c 0],[d 0],[p p],'r')
plot3([0 -c],[0 -d],[p p],'g')
case 'Cytosine'
plot3([c 0],[d 0],[p p],'y')
plot3([0 -c],[0 -d],[p p],'m')
case 'Guanine'
plot3([c 0],[d 0],[p p],'m')
plot3([0 -c],[0 -d],[p p],'y')
end
p = pi/4 + p;
end
% =====================================================================
%Do not change the lines below! They are correct!
view(0,0)
axis([-2 2 -2 2 -1 rna_length])