How do I insert Nan values into a list, if there isn't a file which has a specific name? when exporting column values of multiple files into new file.

2 visualizaciones (últimos 30 días)
Hello,
I am new to Matlab. I am working on one year output data of a detector. I faced problems regarding the data processing procedure. Since then I have been learning matlab.
I have continuously named 365 output files such as 20140101 , 20140102 .... 20140110 (in format of YYYYMMDD) . Each files have same structure as follows :
# comment
# comment
# comment
# comment
# comment
# comment
# comment
# comment
# comment
# comment
# comment
# comment
# comment
# Time (UTC) nV
20140109T000000 006.55
20140109T000030 006.58
20140109T000100 006.60
20140109T000130 006.62
20140109T000200 006.66
...
I need to export values of nV from all output files into one new file in a order. nV has 2880 values. So i need to make new text file which has 1051200 x 2 array data. However, some output files are missing. For examle, lets say i need to plot 10 day datas, however the detector didn't work on the 6th and 8th day so there will be only 8 datas. But since I need to plot time dependant graphic, if there is no output file i want to insert some NaN values or 0 into the new file where nVs are exported. So I was wondering if it is possible?
What I need is a file wich has stucture as follows:
1 006.55 (nV of 20140101)
006.58
...
2 007.59 (nV of 20140102)
007.61
...
3 nV of 20140103
...
4 nV of 20140104
...
5 nV of 20140105
...
6 0 (since there is no output file as 20140106)
0
...
7 nV of 20140107
...
8 0 (since there is no output file as 20140108)
0
...
9 nV of 20140109
...
10 nV of 20140110
...
I have attached 10day sample datas.

Respuestas (1)

Sulaymon Eshkabilov
Sulaymon Eshkabilov el 19 de Oct. de 2021
The data (nV) import and augmentation from the data files can be done using readmatrix(), strcat(). E.g.:
DS =[];
for ii = 1:5
FN = strcat(num2str(20140100+ii), '.txt');
D = readmatrix(FN);
DS = [DS; D(:,2)];
end
D7 = readmatrix('20140107.txt');
D9 = readmatrix('20140109.txt');
D10 = readmatrix('20140110.txt');
DS = [DS; D7(:,2); D9(:,2); D10(:,2)];
  2 comentarios
Nar Gomboo
Nar Gomboo el 19 de Oct. de 2021
Thank you for the answer. I have so many outputs files not only ten. So I need some automation script which reads a file name and copyies the nV value to new text file.
Sulaymon Eshkabilov
Sulaymon Eshkabilov el 19 de Oct. de 2021
Editada: Sulaymon Eshkabilov el 19 de Oct. de 2021
You should use a code as shown here:
P = 'Directory to where the files are stored';
% P=pwd; % Current directory
S = dir(fullfile(P, '*.txt')); % Select the file extension to suit your data files
D = 0;
for k = 1:numel(S)
F = fullfile(P, S(k).name);
D = D + readmatrix(F);
end
DS = D(:,2); % ALL numerical data of nV taken out

Iniciar sesión para comentar.

Categorías

Más información sobre Interactive Control and Callbacks en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by