-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcsv_to_mat.m
67 lines (50 loc) · 1.87 KB
/
csv_to_mat.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
%%%%%%%%%%%%%%%%%%%% .csv to .mat file %%%%%%%%%%%%%%%%
% This file reads the .csv file generated by Paraview and arranges it to be
% readable by MATLAB
clear; clc; close all;
cd D:\computations_dir\oscillating_cylinder\aratio0point1_fratio3point5\postProcessing\plot_over_line_time_z_vorticity;
for i = 1:20
%% specify your file name here
filename = ['stationary_cylinder_validation_08apr2023_' num2str(i) '.csv'];
%%
delimiter = ',';
startRow = 2;
formatSpec = '%f%f%f%f%f%f%f%f%[^\n\r]';
fileID = fopen(filename,'r');
dataArray = textscan(fileID, formatSpec, 'Delimiter', delimiter, 'EmptyValue' ,NaN,'HeaderLines' ,startRow-1, 'ReturnOnError', false);
fclose(fileID);
TimeStep = dataArray{:, 1};
Time = dataArray{:, 2};
Points0 = dataArray{:, 3};
Points1 = dataArray{:, 4};
Points2 = dataArray{:, 5};
U0 = dataArray{:, 6};
U1 = dataArray{:, 7};
U2 = dataArray{:, 8};
% Clear temporary variables
clearvars filename delimiter startRow formatSpec fileID dataArray ans;
%% construct a table
augment = [TimeStep,Time,Points0,Points1,Points2,U0,U1,U2];
%yourtable = array2table(augment);
%sorted_table = sortrows(yourtable,[3 4]);
%sorted_array =table2array(sorted_table);
%%
%x = sorted_array(:,3); y = sorted_array(:,4);
u_velo = augment(:,5); v_velo = augment(:,6); w_velo = augment(:,7);
u_net = sqrt(u_velo.^2+v_velo.^2+w_velo.^2);
xrange = min(augment(:,3)):0.05:max(augment(:,3));
yrange = min(augment(:,4)):0.05:max(augment(:,4));
[xq,yq] = meshgrid(xrange,yrange);
[r,c] = find(u_net == 0);
u_net(r,c) = NaN;
% Interpolate the scattered data on the grid. Plot the results.
vq = griddata(augment(:,3),augment(:,4),u_net,xq,yq);
pcolor(xq,yq,vq); shading interp;
xlabel('x [m]');
ylabel('y [m]');
title('U [m/s], z = 0 plane');
colorbar;
colormap(parula);
writeVideo(writerObj, getframe(gcf));
end
close(writerObj);