How to find a numerical value in text file and get an output from that row?

3 views (last 30 days)
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

Accepted Answer

Image Analyst
Image Analyst on 22 Apr 2015
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 Comments
Punit Gandhi
Punit Gandhi on 22 Apr 2015
Thank you. It works and I can get the exact value I want. I have one more problem. Now, I want to check the result only for a specific value of date. That is if I want to check the maxProduction only for rows with date value 23, how can that be done?
Image Analyst
Image Analyst on 22 Apr 2015
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, :);

Sign in to comment.

More Answers (0)

Categories

Find more on Financial Toolbox in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!