# How to extract the unique value from column 1, with the highest corresponding value from column 2 and the adjacent time value from column 3?

2 views (last 30 days)
muhammad choudhry on 23 Dec 2022
Answered: Image Analyst on 23 Dec 2022
Hi,
In the attached file, column 1 have head values in which each number have a repetition, for example 0,0,0, few times then 1,1,1,1 few times but in the adjacent column flowrate values are different fro each head value. I am looking to extract the head value with the highest corresponding flowrate value and the adjacent time. I am googling and not been able to find anything so far I would appreciate your help. I know how to do it in excel using unique, index and match function but since I have alot of files matlab script will help alot.
Rik on 23 Dec 2022
This is probably not too difficult to implement with a loop. What have you tried so far? Which part are you stuck? Do you know how to import your data to a Matlab variable? What code did you attempt to write to get to your desired result?

Robin on 23 Dec 2022
Moved: Image Analyst on 23 Dec 2022
To extract the head value with the highest corresponding flowrate value and the adjacent time in a matrix in MATLAB, you can use the max function along with the find and ind2sub functions. Here is an example of how to do this:
Copy code
% Define the matrix
A = [column 1 values, column 2 values, column 3 values];
% Find the maximum flowrate value and its indices
[maxFlowrate, maxFlowrateIndex] = max(A(:, 2));
[maxFlowrateRow, maxFlowrateCol] = ind2sub(size(A), maxFlowrateIndex);
% Extract the head value and time corresponding to the maximum flowrate value
timeValue = A(maxFlowrateRow, 3);
% Print the results
This code first finds the maximum flowrate value and its indices using the max function. It then converts the linear indices to row-column indices using the ind2sub function. Finally, it extracts the head value and time values from the corresponding row and prints the results to the command window.
I hope this helps! Let me know if you have any questions.

Image Analyst on 23 Dec 2022
I am not seeing that in column 1. I see
fileName = 'SCURVE.xlsx';
Time Head Flowrate Filter ____ ____ ________ ______ 0 0 0 NaN 0.1 0 0 NaN 0.2 0.01 0 NaN 0.3 0.01 0 NaN 0.4 0.02 0 NaN 0.5 0.02 0 NaN 0.6 0.02 0 NaN 0.7 0.03 0 NaN
Where are the runs of 0's, then 1's, etc.? Evidently not in column 1 like you say. Not even in column 2, the "Head" column. And the Head values are not just runs of integers like 0, 1, 2, 3, etc. They are fractional numbers, though some are repeated.
Anyway, I think you can probably use these functions: findgroups, splitapply, grpstats, or groupsummary