2

タブ区切りのテキスト ファイルを読み取る必要があり、出力が matlab 構造でなければならない課題に取り組んでいます。

ファイルの内容は次のようになります (少し乱雑ですが、画像が得られます)。実際のファイルには、500 個の遺伝子 (Analyte 1 から始まる行) と 204 個のサンプル (A2 から始まる列) が含まれています。

#1.2                                    
500 204                             
Name        Desc        A2  B2  C2  D2  E2  F2  G2  H2
Analyte 1   Analyte 1   978 903 1060    786 736 649 657 733.5
Analyte 2   Analyte 2   995 921 995.5   840 864.5   757 739 852
Analyte 3   Analyte 3   1445.5  1556.5  1579    1147.5  1249    1069.5  1048    1235
Analyte 4   Analyte 4   1550    1371    1449    1127    1196    1337    1167    1359
Analyte 5   Analyte 5   2074    1776    1960    1653    1544    1464    1338    1706
Analyte 6   Analyte 6   2667    2416.5  2601    2257    2258    2144    2173.5  2348
Analyte 7   Analyte 7   3381.5  3013.5  3353    3099.5  2763    2692    2774    2995

私のコードは次のとおりです。

fid = fopen('gene_expr_500x204.gct', 'r');%Open the given file

% Skip the first line and determine the number or rows and number of samples
dims = textscan(fid, '%d', 2, 'HeaderLines', 1);
ncols = dims{1}(2);

% Now read the variable names
varnames = textscan(fid, '%s', 2 + ncols);
varnames = varnames{1};

% Now create the format spec for your data (2 strings and the rest floats)
spec = ['%s%s', repmat('%f', [1 ncols])];

% Read in all of the data using this custom format specifier. The delimiter     will be a tab
data = textscan(fid, spec, 'Delimiter', '\t');

% Place the data into a struct where the variable names are the fieldnames
ge = data{3:ncols+2}
S = struct('gn', data{1}, 'gd', data{2}, 'sid', {varnames});

ge に関する部分は私の現在の試みですが、実際には機能していません。どんな助けでも大歓迎です、事前に感謝します!!

4

1 に答える 1