Sunday, 12 April 2020

Encode and Decode

Hi All

function pushbutton17_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton17 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
[filename pathname]=uigetfile({'*.txt'},'file selctor');
fullpathname=strcat(pathname,filename);
text=fileread(fullpathname);
ASCII = double(text)
A=dec2bin(ASCII,8)

B= logical(A - 48)

 m=size(B,1)
 n=size(B,2)

p='A'
q='C'
r='G'
S= 'T'

k=1
 x=.4;
h=waitbar(x,'Process start');
for i=1:m
for j=1:2:n
if (B(i,j)==0 && B(i,j+1)==1)
sc(k)=p
elseif (B(i,j)==1 && B(i,j+1)==0)
sc(k)=q
elseif (B(i,j)==0 && B(i,j+1)==0)
sc(k)=r
else
sc(k)=S
end
k=k+1
end
end
%p53nt = fastaread('p53nt.txt')
L = get(handles.text50,'String');
j=1
for i=1:4:length(sc)
k=strfind(L,sc(i:i+3))

code(j)=k(randi([1 length(k)]));
j=j+1;
end


fileID = fopen('Ciphertext.txt','w');
for (i=1:length(code))
fprintf(fileID,'%d ',code(i))
end
rawdata1=load(['Ciphertext.txt']);
fclose(fileID)
pause(3)
waitbar(x+.6, h, 'Completed');

% --- Executes on button press in pushbutton18.
function pushbutton18_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton18 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
x=.4;
h=waitbar(x,'Process start');
fileID = fopen('Ciphertext.txt','r');
fileID2 = fopen('Plaintext.txt','w');

a=fscanf(fileID,'%d');
L = get(handles.text50,'String');
seq=L
%p53nt = fastaread('p53nt.txt')
%seq=p53nt.Sequence;
for i=1:1:length(a)
    seq4='';
    %Generate 4 DNA charaters for a number in file
    if(seq(a(i))=='A')
        seq4=strcat(seq4,'01');
    elseif(seq(a(i))=='G')
        seq4=strcat(seq4,'00');
    elseif(seq(a(i))=='C')
        seq4=strcat(seq4,'10');
    elseif(seq(a(i))=='T')
        seq4=strcat(seq4,'11');
    end
       
    if(seq(a(i)+1)=='A')
        seq4=strcat(seq4,'01');
    elseif(seq(a(i)+1)=='G')
        seq4=strcat(seq4,'00');
    elseif(seq(a(i)+1)=='C')
        seq4=strcat(seq4,'10');
    elseif(seq(a(i)+1)=='T')
        seq4=strcat(seq4,'11');
    end
   
    if(seq(a(i)+2)=='A')
        seq4=strcat(seq4,'01');
    elseif(seq(a(i)+2)=='G')
        seq4=strcat(seq4,'00');
    elseif(seq(a(i)+2)=='C')
        seq4=strcat(seq4,'10');
    elseif(seq(a(i)+2)=='T')
        seq4=strcat(seq4,'11');
    end
   
    if(seq(a(i)+3)=='A')
        seq4=strcat(seq4,'01');
    elseif(seq(a(i)+3)=='G')
        seq4=strcat(seq4,'00');
    elseif(seq(a(i)+3)=='C')
        seq4=strcat(seq4,'10');
    elseif(seq(a(i)+3)=='T')
        seq4=strcat(seq4,'11');
    end   
%     seq4=strcat(seq4,seq(a(i)));
%     seq4=strcat(seq4,seq(a(i)+1));
%     seq4=strcat(seq4,seq(a(i)+2));
%     seq4=strcat(seq4,seq(a(i)+3));
    disp(seq4);
    d1=bin2dec(seq4);
    c1=char(d1);
    fprintf(fileID2,'%s ',c1);
end
fclose(fileID);
fclose(fileID2);
pause(3)
waitbar(x+.6, h, 'Completed');

Tuesday, 16 October 2018

SVM Classification code in Matlab


 Hi All,

See a simple SVM training and testing module

// Here a student performance prediction is done

//Three inputs are marks for series1, series2 and attendance percentage

//1 indicates pass and 0 indicates fail
//Testing with [25 30 and 35

//result will be stored in classes

train1=[75 81 82 ; 30 21 40];  // Training Data

test1=[25 30 35]; // Testing Data

G=[1 0];   // Label for Training data

G=G'; // Converting to column vector

svmStruct = svmtrain(train1,G,'Kernel_Function','rbf','Method','QP');  // Create an SVM model with training data

classes = svmclassify(svmStruct,test1);  // Classification using Test data

classes  // Display output label

Decision Tree Classification in Matlab

Hi All,

Please use the code for Decision Tree Classification


---------------------------------------------------------------

train1=[30 56 1 1 1 ; 31 10 1 1 1;10 1 60 1 1;14 1 30 1 3 ; 14 1 30 1 17;6 1 25 6 1;6 1 25 17 1]; // Training Set

G=[0 1 0 0 1 0 1]; // Labels of Training data

Mdl = fitctree(train1,G); // Training Decision Tree

test1=[30 63 1 1 1]; // Testing data

hup=predict(Mdl,test1); // Testing the decision tree

--------------------------------------------------------------

Sunday, 6 November 2016

Matlab for researach

Hi All,

Matlab is really useful for doing research.
I shall come back with more on this.

Bye