从1x1单元阵列中提取数据

时间:2017-11-30 12:00:16

标签: matlab

我使用 textscan 将.txt文件读入1x1单元格数组。如何从1x1单元阵列中提取某些数据?

.txt文件包含混合格式数据。

到目前为止我的代码:

%% Import Safir output file
    
    FileName="PROOV_6.txt";
    tic

%% Read the txt file
        FID = fopen(FileName, 'r');
            if FID == -1
                error('Cannot open file')
            end
        Data = textscan(FID, '%s', 'delimiter', '\n', 'whitespace', ' ' );
        CStr = Data{1};
        fclose(FID);
        
%% Find all row numbers that contain the string
        Index = strfind(CStr, 'TOTAL TEMPERATURES');
        IndexA = find(not(cellfun('isempty', Index)));
                           
%% Loop through CStr accessing matrices between strings "TOTAL TEMPERATURES"

%% ---------- 
       
%% Save the file again
        FID = fopen(FileName, 'w');
            if FID == -1
                error('Cannot open file')
            end
        fprintf(FID, '%s\n', CStr{:});
        fclose(FID);
    toc

我还将提供.txt文件的链接: PROOV_6.txt

1 个答案:

答案 0 :(得分:0)

使用{}索引从单元格数组中获取值。只有一个细胞没有区别。 mycell{1}

相关问题