フィルターのクリア

modify a data file using MATLAB?

9 ビュー (過去 30 日間)
kimy
kimy 2021 年 6 月 28 日
コメント済み: kimy 2021 年 7 月 19 日
Hi guys,
I am a beginner of MATLAB. Now I have a series of data files output from Openfoam, in terms of different time step (shown in floowing figure). A
and under each folder I have the data included in the file like below. However I only need the column of x and p for each file.
I would like to integrate the files in one separate file and add a second colum between x and p, by t (t=0.5, 1, 1.5 ....)., shown in following format. I have no experience of modyfing a file. Could you please give me some tips, thanks a lot.
%x t value
0 0.5 3000
1 0.5 3200
...
20 30 3690
  2 件のコメント
Mathieu NOE
Mathieu NOE 2021 年 6 月 28 日
hello
could you share some of the data file ?
tx
kimy
kimy 2021 年 6 月 28 日
for sure. Thanks for your reply.
Original files are sampleDict.zip whereas the p_gorund.csv is what I want (this file was made manually)

サインインしてコメントする。

採用された回答

Mathieu NOE
Mathieu NOE 2021 年 6 月 28 日
so this is it !
hope it helps
see the attached file too - you will need them to have the folders sorted in natural order , which is not what matlab does "naturally" , so to say
main code :
clc
clearvars
S = dir('**/*.raw');
[m,n] = size(S);
%% first we have to sort the folders in natural order - otherwise the time steps
% will not be uniformly increasing
for ci = 1:m
folders{ci} = S(ci).folder;
filenames{ci} = S(ci).name;
end
[folders_sort,ndx,dbg] = natsort(folders);
filenames_sort = filenames(ndx);
%% main loop for data extraction and concatenation
outdata = [];
for k = 1:m
foldername = char(folders_sort(k)) % display in command window the folder name
filename = char(filenames_sort(k)) % display in command window the file name
if strcmp(foldername(end-1:end),'\0')
% do nothing (skip t = 0 results)
else
F = fullfile(foldername, filename);
data = importdata(F, ' ', 2);
data = data.data;
[m,n] = size(data);
% get the simulation time step value from folder name
ind = strfind(foldername,'\');
time_step = str2num(foldername(ind(end)+1:end));
tmp = [data(:,1) time_step*ones(m,1) data(:,4)];
% now vertical concatenation of all files data
outdata = [outdata ; tmp];
end
end
%% export data
T = array2table(outdata);
T.Properties.VariableNames(1:3) = {'%x','t','p'} % %x t p
writetable(T,'file1.csv')
  7 件のコメント
kimy
kimy 2021 年 7 月 15 日
編集済み: kimy 2021 年 7 月 15 日
yes, I have two types of data output (sampleDict and toppressure), but I need rearrange them like the format shown in "finaldata" based on any one of two data file..
kimy
kimy 2021 年 7 月 19 日
Anyone has ideas?

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeFile Operations についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by