フィルターのクリア

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

1 回表示 (過去 30 日間)
Punit Gandhi
Punit Gandhi 2015 年 4 月 22 日
コメント済み: Image Analyst 2015 年 4 月 22 日
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

採用された回答

Image Analyst
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 件のコメント
Punit Gandhi
Punit Gandhi 2015 年 4 月 22 日
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 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 ExchangeFinancial Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by