许可优化
许可优化
产品
产品
解决方案
解决方案
服务支持
服务支持
关于
关于
软件库
当前位置:服务支持 >  软件文章 >  合并OUT文件,解决Fluent在动态计算中出错重开导致的监测out文件不连续的问题

合并OUT文件,解决Fluent在动态计算中出错重开导致的监测out文件不连续的问题

阅读数 3
点赞 0
article_banner


两个不够就自己加吧,逻辑一样的

% Define file paths

file1 = 'st-rfile.out&#​39;;

% file2 = 'all_1_15611.out&#​39;;

% Open the first file, read the header, and then read the data

fid1 = fopen(file1, 'rt&#​39;);

if fid1 == -1, error('Cannot open file %s&#​39;, file1); end

fgetl(fid1); % Skip the first line

fgetl(fid1); % Skip the second line

headerLine = fgetl(fid1); % Read the header line

headerLine = strrep(headerLine, '(&#​39;, '&#​39;); % Remove left parentheses

headerLine = strrep(headerLine, ')&#​39;, '&#​39;); % Remove right parentheses

headers = strsplit(headerLine, '&#​34; "&#​39;); % Split the header line into individual column names

headers = strrep(headers, '&#​34;', &#​39;'); % Remove double quotes from headers

headers = headers(~cellfun('isempty&#​39;, headers)); % Remove any empty cells

data1 = [];

while ~feof(fid1)

   line = fgetl(fid1); % Read each line

   if ~ischar(line), break; end % If it's not a character line, stop

   nums = sscanf(line, '%f&#​39;); % Parse the numbers

   data1 = [data1; nums.'];

end

fclose(fid1);

% Open the second file and read the data

fid2 = fopen(file2, 'rt&#​39;);

if fid2 == -1, error('Cannot open file %s&#​39;, file2); end

fgetl(fid2); % Skip the title row

fgetl(fid2); % Skip the second row

fgetl(fid2); % Skip the header row as it is the same as the first file

data2 = [];

while ~feof(fid2)

   line = fgetl(fid2); % Read each line

   if ~ischar(line), break; end % If it's not a character line, stop

   nums = sscanf(line, '%f&#​39;); % Parse the numbers

   data2 = [data2; nums.'];

end

fclose(fid2);

% Find the overlapping part in the second file with the first file

overlap_idx = find(data2(:,1) <= data1(end, 1), 1, &#39;last&#​39;);

% Combine data

combined_data = [data1; data2(overlap_idx+1:end, :)]; % Skip the overlapping part

% Validate that the number of headers matches the number of data columns

if size(combined_data, 2) ~= length(headers)

   error('The number of headers does not match the number of columns in the data.');

end

% Create a table with headers and combined data

combined_data_table = array2table(combined_data, &#39;VariableNames&#​39;, headers);

% Extract the file name without extension from file1

[filepath, name, ~] = fileparts(file1);

% Construct the new file name with the extracted name and .csv extension

output_filename = fullfile(filepath, [name, &#39;.csv&#​39;]);

% Export the table to a CSV file with the new file name

writetable(combined_data_table, output_filename);


免责声明:本文系网络转载或改编,未找到原创作者,版权归原作者所有。如涉及版权,请联系删

相关文章
技术文档
QR Code
微信扫一扫,欢迎咨询~
customer

online

联系我们
武汉格发信息技术有限公司
湖北省武汉市经开区科技园西路6号103孵化器
电话:155-2731-8020 座机:027-59821821
邮件:tanzw@gofarlic.com
Copyright © 2023 Gofarsoft Co.,Ltd. 保留所有权利
遇到许可问题?该如何解决!?
评估许可证实际采购量? 
不清楚软件许可证使用数据? 
收到软件厂商律师函!?  
想要少购买点许可证,节省费用? 
收到软件厂商侵权通告!?  
有正版license,但许可证不够用,需要新购? 
联系方式 board-phone 155-2731-8020
close1
预留信息,一起解决您的问题
* 姓名:
* 手机:

* 公司名称:

姓名不为空

姓名不为空

姓名不为空
手机不正确

手机不正确

手机不正确
公司不为空

公司不为空

公司不为空