Code for extracting the special values
2 次查看(过去 30 天)
显示 更早的评论
Hi all,
I have txt file which contains two columns: the first column is time [hourly resolution], and the second column is the answer of my function (values). I want to extract the values from the second column which are based on daily [I mean 0,1,2,3,...]. and then write it in another txt file, which will have two columns and be like: 0 814 1 745 2 660 3 539 . .
How should I have to write my code? Attached my .txt file here.
I appreciate any help and thanks in advance. Hope to hear from you. Sepideh
0 个评论
采纳的回答
Stephen23
2016-2-2
编辑:Stephen23
2016-2-2
% Read original data file:
M = dlmread('remaining particles total.txt','\t');
H = min(M(:,1)):max(M(:,1));
[X,Y] = ismember(H,M(:,1));
assert(all(X),'Some hour values are missing')
% Write new data file:
fid = fopen('newfile.txt','wt');
fprintf(fid,'%d\t%d\n',M(Y,:).');
fclose(fid);
This creates the following new text file:
0 814
1 745
2 660
3 539
4 420
5 355
6 303
... lots here
1821 0
1822 0
1823 0
1824 0
1825 0
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Text Data Preparation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!