MATLAB读取TECPLOT笛卡尔网格三维流场数据
基于笛卡尔网格的三维流动数值模拟,其流场信息可以通过tecplot格式进行输出,方便tecplot对流场进行可视化处理,但对数据进行在加工时,还是导入matlab中比较方便,那么对于一个tecplot数据文件,matlab是不能直接读取的,必须有一个函数将tecplot数据文件中数据转换成matlab便于操作的数据格式。
tecplot数据文件前三行是文件头,其中第一行是数据文件说明,第二行中是文件中所定义的变量名,第三行,对于笛卡尔网格的流场,其包含了每个空间方向上离散的数据数目。通过处理第二行文本,可以获取所定义的变量及其数目。
tecplot文件中数据一行是一个记录,一行中数据的顺序和文件头中第二行定义的变量顺序相对应,通常前三个数据是x,y,z,对应网格点空间位置。
Title= "simulation data"
VARIABLES= "X","Y","Z","U","V","W","RHO"
ZONE T= "BOX",I= 100,J=321,K=100,F= POINT
0 0 0 0.000252868 0.00386761 -0.00194455 1000.01
1 0 0 -0.000252631 -0.00258331 0.00188909 1000.01
2 0 0 0.000252594 0.00441002 -0.00183506 1000.01
3 0 0 -0.000252256 -0.0019755 0.00178188 1000
4 0 0 0.000252931 0.00492305 -0.00173004 1000
...
1、matlab读取tecplot文件,通过读取文件头获取文件所定义变量以及变量数目,同时读取文件中所包含数据信息,所读取的数据保存在一个四维数组中,最后一个维度代表每个变量,变量名保存在一个元胞数组中。
1.1 tecplot数据为空间三维流场,tecplot2mat_3D
% read data from tecplot file, and save the variables to mat % filename: the name of the tecplot file including the extensions % var: the data of variables, is a four dimensions array, the last dimension is the the number of variable % var_name: the name of the variables, is a cell % var_num: the number of the variables function [var,var_name,var_num] = tecplot2mat_3D(filename) %% tecplot data file read % open the file fid = fopen(filename);% read the second line of data file [~] = fgetl(fid); str = fgetl(fid);% get the number of the variables o1 = regexpi(str,'"','start'); var_num = length(o1)/2;% get the name of the variables var_name = cell(1,var_num); for i = 1:var_numvar_name{1,i} = str(o1(2*i-1)+1:o1(2*i)-1); end% read the data strformat = repmat('%f',1,var_num); data = textscan(fid,strformat,'headerlines',1); data = cell2mat(data);% close the file fclose(fid);%% reshape data % get discrete points xi = sort(unique(data(:,1))); yi = sort(unique(data(:,2))); zi = sort(unique(data(:,3)));% number of the discrete points num_x = length(xi); num_y = length(yi); num_z = length(zi);% initialize the three demonsions array var = zeros(num_x,num_y,num_z,var_num);% assignment the array according to the data for n = 1:size(data,1)% method 1: we don't know the relationship between the number and the index, we must find the index according to the value % index_x = find( data(n,1) == xi );% index_y = find( data(n,2) == yi );% index_z = find( data(n,3) == zi );% method 2: we know the relationship between the value and the index, we can directly access the index index_x = data(n,1) + 1;index_y = data(n,2) + 1;index_z = data(n,3) + 1;% access the datafor i = 1:var_numvar(index_x,index_y,index_z,i) = data(n,i);end endfprintf('reshape the data\n');%% data save to mat index_str = find( '.' == filename ); if isempty(index_str) elsefilename = filename( 1:index_str-1 ); end eval(['save ',filename,'.mat var var_name var_num;']);fprintf('save the data\n'); end
1.2 tecplot数据为空间二维流场,tecplot2mat_2D
% read data from tecplot file, and save the variables to mat % filename: the name of the tecplot file including the extensions % var: the data of variables, is a three dimensions array, the last dimension is the the number of variable % var_name: the name of the variables, is a cell % var_num: the number of the variables, is a number function [var,var_name,var_num] = tecplot2mat_2D(filename) %% tecplot data file read % open the file fid = fopen(filename);% read the second line of data file [~] = fgetl(fid); str = fgetl(fid);% get the number of the variables o1 = regexpi(str,'"','start'); var_num = length(o1)/2;% get the name of the variables var_name = cell(1,var_num); for i = 1:var_numvar_name{1,i} = str(o1(2*i-1)+1:o1(2*i)-1); end% read the data strformat = repmat('%f',1,var_num); data = textscan(fid,strformat,'headerlines',1); data = cell2mat(data);% close the file fclose(fid);%% reshape data % get discrete points xi = sort(unique(data(:,1))); yi = sort(unique(data(:,2)));% number of the discrete points num_x = length(xi); num_y = length(yi);% initialize the three demonsions array var = zeros(num_x,num_y,var_num);% assignment the array according to the data for n = 1:size(data,1)% method 1: we don't know the relationship between the number and the index, we must find the index according to the value% index_x = find(data(n,1) == xi);% index_y = find(data(n,2) == yi);% method 2: we know the relationship between the value and the index, we can directly access the index index_x = data(n,1) + 1;index_y = data(n,2) + 1;% access the datafor i = 1:var_numvar(index_x,index_y,i) = data(n,i);end endfprintf('reshape the data\n');%% data save to mat index_str = find( '.' == filename ); if isempty(index_str) elsefilename = filename( 1:index_str-1 ); end eval(['save ',filename,'.mat var var_name var_num;']);fprintf('save the data\n'); end
2、测试脚本,读取给定的TECPLOT文件名,输出文件包含数据以及将文件中定义的变量加载到MATLAB工作区
clc;clear; close all;filename = 'U3D.dat'; [var,var_name,var_num] = tecplot2mat_3D(filename);for i = 1:var_numeval([var_name{1,i},'=var(:,:,:,i);']); end
3、测试结果,tecplot文件定义的变量就全部加载到工作区了。
转载于:https://www.cnblogs.com/kljfdsa/p/7845816.html
MATLAB读取TECPLOT笛卡尔网格三维流场数据相关推荐
- matlab二维笛卡尔坐标系
matlab绘制二维笛卡尔坐标系 这是一个经常会用到的程序,根据散点数据画出折线图,希望对你有帮助,O(∩_∩)O哈哈~. 主程序(main.m) clc;clear;close all; %% 绘制 ...
- matlab输入excel高版本,『matlab读取excel指定列』excel中大量数据如何导入matlab当中?超过1000个数据无法一个一个输入...
如何将excel表格中大量数据导入matlab中并作图 哈哈,选我吧!使用xlsread函数体的语法你在帮助里面搜索xlsread就可以了.我要是现在回答也接翻译帮助文件.xlsread的参数有文件表 ...
- matlab读取心电注释.qrs文件格式,MIT-BIH ECG 心电数据的下载和读取图解 - 晨宇思远 - CSDN博客...
MIT-BIH ECG 心电数据的下载和读取图解 收藏 一.如何下载获取MIT-BIH的数据 从下面这个官方链接页面可以下载到所有48组MIT-BIH心电数据: 下面这个链接是MIT-BIH数据库的详 ...
- 【小技巧】使用MATLAB读取quartusii中signaltapII保存的tbl格式数据文件
有的时候,我们需要将FPGA采集到的数据进行显示,通过MATLAB分析,那么需要读取FPGA的片上数据.我们以quartusii为例子,其片上数据采集到的文件格式为tbl文件,这个时候,我们编写如下程 ...
- matlab 汽车 流场,matlab画流场图
基于 Matlab 分布式工具箱的流场计算及其可视化 蔡群;周美莲;段杰峰;李青... 基于 MATLAB 和 CFD 数据库的流场可视化的实现 [J], 晏畅 5.基于 VB 与 MATLAB 混合 ...
- matlab流场可视化后处理
matlab流场可视化后处理 1流体中标量的可视化 1.1 云图 1.2 切片图绘制 1.3 三维等值面图绘制 2流体中矢量的可视化 2.1 箭头图或速度图 2.2 流线图 2.4 带节点的流线图 2 ...
- python绘制笛卡尔心形曲线_如何在python的极图中显示笛卡尔系统?
在这里,我试图将极坐标图添加到笛卡尔网格的顶部,但是我得到的是2个单独的图形(一个极坐标另一个笛卡尔坐标),我希望将此极坐标图嵌入到笛卡尔坐标图中.我还使用了一些以前可用的代码,因为我是matplot ...
- ORACLE SQL笛卡尔集
ORACLE SQL笛卡尔集 开发工具与关键技术:Oracle sql*plus PLSQL Developer 作者:何任贤 撰写时间:2019年01月01日 笛卡尔集是所有表连接中最特殊的一个,它 ...
- matlab数据变成一列数据,matlab读取excel表格列数据-matlab导入excel后,怎么把数据提取成一列?...
怎么用matlab读取excel表格中的一列十六进制数据? x=xlsread('oillack.xls','sheet1','a1:a73') excel文件名是oillack.xls,sheet1 ...
最新文章
- 粒子群优化算法_每日论文19:粒子群优化算法综述
- mysql key_block_size_Mysql入门mysql Key_buffer_size参数的优化设置
- JavaScript实现跳跃游戏的动态编程自上而下的方法算法(附完整源码)
- 【2018北京集训(六)】Lcm
- iOS Cookie学习(NSHTTPCookieStorage的使用)
- DIY 主机 所有AMD IntelCPU及主板
- Spring Boot笔记-JPA自定义SQL语句参数为对象时如何操作
- 宝塔可以修改服务器内存限制吗,宝塔内存使用率很高的解决方法 cpu过高这样做!...
- matlab 动画_MATLAB的动画制作和视频录制
- python走起之第十三话
- oracle中jason串,在oracle中使用json
- python词云图输出(附代码)
- ttl低电平接大电阻_电压不稳定?那是你不懂上拉/下拉电阻原理,5分钟教你应用!...
- 川土微 数字隔离器 CA-IS3722HS可替代ADUM1201ARZ
- spdif数字传输规范
- 《途客圈创业记:不疯魔,不成活》一一2.5 完善拼图
- 计算机专业世界排名,2021计算机科学专业世界排名重磅出炉!CMU登顶,清华挺进前五...
- python数据分析库pandas-三、: python数据分析处理库-Pandas
- 异步与promise
- 上汽集团进军网约车市场 滴滴的市场地位会被传统车企们挑战成功吗?