string cell array
================
ar = {'aa';'bbbbb'}
mat2str (convert number to string)
======================
parameter = '-s 0 -t 0 -c ';
for c=1:2
nextp = [parameter mat2str( c) ]
end
string comparison
================
sa='ab';
sb='aba';
t = strcmp(sa , sb )
if( t == 1)
display('Yest match');
else
display('No match')
end
strmatch find exact string in cell array
=======================
list = {'max', 'minimax', 'maximum', 'max'}
x = strmatch('max',list,'exact')
find string starts with in cell array
=======================
list = {'max', 'minimax', 'maximum', 'max'}
x = strmatch('max',list)
String Comparison
================
strmatch('ab' , 'abc') ; % return 1
strcmp('ab' , 'abc') ; % return0
Find index of char/ string strfind find the pattern
====================
S = 'Find the starting indices of the pattern string'; strfind(S, 'in') ans = 2 15 19 45
Sub String
===================
s = s(1 : n)
String trim
==========out = strtrim(ins)
Reading from file % parse each line
===========================
function createLogo
motifCount=0;
fNamePPM = '../gene.features.v2/v2_C_287_NC_48_profile.model'; % columns as Letter
fid = fopen(fNamePPM);
tline = fgets(fid);
while ischar(tline)
if tline(1) =='*' % start of a motif
motifCount = motifCount + 1;
tline = fgets(fid); % read ID
%% tokenize the line
remain = tline;
countToken = 0;
while true
[word, remain] = strtok(remain);
if isempty( word )
break;
end
countToken = countToken +1;
if countToken ==2
motifLen = str2num(word);
profileMatrix = zeros(4,motifLen);
end
disp( word );
end
tline = fgets(fid); % score
tline = fgets(fid); % A
profileMatrix(1,1:motifLen) = str2num(tline);
end
tline = fgets(fid); % to read for next iteration
end
fclose(fid);
end
String tokenizer ( strtok )
==============
remain = wholeString;
while true
[word, remain] = strtok(remain);
if isempty(
word ), break; end
disp(
word );
end
% convert tab delimited line into vector of number
=====================================
myvector = str2num( myLine );
Read file with FIXED COLUMN like matrix but content may be string
fid = fopen('scan1.dat');
C = textscan(fid, '%d\t%f\t%f\t%f\t%f'); % each row have 5 column
C{1} (1) ; % first column , 1st row
C{1} (2) ; % first column , 2nd row
fclose(fid);
fid = fopen('scan1.dat');
C = textscan(fid, '%d\t%f\t%f\t%f\t%f'); % each row have 5 column
C{1} (1) ; % first column , 1st row
C{1} (2) ; % first column , 2nd row
fclose(fid);
[ covTarget covBG score source consensus ] = textread(fnameStat,'%f\t%f\t%f\t%s\t%s');
% here in the file there are 5 columns , first 3 are numeric, and last 2 are string
Write cell Array dlmwrite is not for cell array
fid = fopen('LLGencodeCommonID.txt', 'w');
fprintf(fid, '%s\n', commonID{2}); % write 2nd column
fclose(fid);
sscanf: Parsing word inside of a string
=====================
consensusSeq = fgetl(fid) % Consessus: AAACC
curSeq = sscanf(consensusSeq,'%*s %s', [1, inf]) % curSeq = AAACC
Comments
Post a Comment