How to find a numerical value in text file and get an output from that row?
2 次查看(过去 30 天)
显示 更早的评论
I have a text file in which I save data after each iteration. Now, I want to find a maximum value in the Production column. After which I would like to analyse that row and get the value of Date and Time from the textfile. I have pasted a sample text file.
Date Time(24hr) Carbon Money Grid Batt Production Consumption Solar Radiation Wind
23 1 1.18778 0.497751 0 479.97 2.16413 22.1939 0 0 2.16413
23 2 1.18778 0.497751 0 459.941 2.16413 22.1939 0 0 2.16413
23 3 1.18778 0.497751 0 479.97 2.16413 22.1939 0 0 2.16413
23 4 1.18778 0.497751 0 479.97 2.16413 22.1939 0 0 2.16413
23 5 1.18778 0.497751 0 479.97 2.16413 22.1939 0 0 2.16413
23 6 1.18778 0.497751 0 479.97 2.16413 29.0000 0 0 2.16413
23 7 1.18778 0.497751 0 479.97 2.16413 22.1939 0 0 2.16413
23 8 1.18778 0.497751 0 479.97 2.16413 22.1939 0 0 2.16413
23 9 1.18778 0.497751 0 459.941 2.16413 22.1939 0 0 2.16413
23 10 1.18778 0.497751 0 479.97 2.16413 22.1939 0 0 2.16413
23 11 1.18778 0.497751 0 479.97 2.16413 22.1939 0 0 2.16413
23 12 1.18778 0.497751 0 479.97 2.16413 22.1939 0 0 2.16413
23 13 1.18778 0.497751 0 479.97 2.16413 22.1939 0 0 2.16413
23 14 1.18778 0.497751 0 479.97 2.16413 22.1939 0 0 2.16413
23 15 1.18778 0.497751 0 459.941 2.16413 22.1939 0 0 2.16413
23 16 1.18778 0.497751 0 479.97 2.16413 22.1939 0 0 2.16413
23 17 1.18778 0.497751 0 479.97 2.16413 22.1939 0 0 2.16413
23 18 1.18778 0.497751 0 479.97 2.16413 22.1939 0 0 2.16413
23 19 1.18778 0.497751 0 479.97 2.16413 22.1939 0 0 2.16413
23 20 1.18778 0.497751 0 479.97 2.16413 22.1939 0 0 2.16413
23 21 1.18778 0.497751 0 459.941 2.16413 22.1939 0 0 2.16413
23 22 1.18778 0.497751 0 479.97 2.16413 22.1939 0 0 2.16413
23 23 1.18778 0.497751 0 479.97 2.16413 22.1939 0 0 2.16413
23 24 1.18778 0.497751 0 479.97 2.16413 22.1939 0 0 2.16413
24 0 1.18778 0.497751 0 479.97 2.16413 22.1939 0 0 2.16413
24 1 1.18778 0.497751 0 479.97 2.16413 22.1939 0 0 2.16413
24 2 1.18778 0.497751 0 479.97 2.16413 22.1939 0 0 2.16413
24 3 1.18778 0.497751 0 479.97 2.16413 27.1939 0 0 2.16413
24 4 1.18778 0.497751 0 479.97 2.16413 29.1939 0 0 2.16413
24 5 1.18778 0.497751 0 479.97 2.16413 22.1939 0 0 2.16413
24 6 0.31999 0.134095 0 479.016 0.583023 21.5671 0 0 0.583023
24 7 0.31999 0.134095 0 479.016 0.583023 21.5671 0 0 0.583023
24 8 0.31999 0.134095 0 479.016 0.583023 21.5671 0 0 0.583023
0 个评论
采纳的回答
Image Analyst
2015-4-22
I presume you still have your array after writing it out to the text file. If not, read it back in. Then get the row
% Get row where production is max
[maxProduction, rowOfMax] = max(yourArray(:, 7));
% Now extract the whole row
thisROw = yourArray(rowOfMax, :);
2 个评论
Image Analyst
2015-4-22
If it works, can you go ahead and "Accept this answer" so I get credit for it? Thanks in advance.
For the second question, I don't know what you mean by "check", but to get all the rows with 23 as the date, you can do this:
rowsWith23date = yourArray(:, 1) == 23;
% Now get the sub array of yourArray with only those rows
subArray23 = yourArray(rowsWith23date, :);
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Financial Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!