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?

1 次查看(过去 30 天)
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.
Thanks in advance for help
  1 个评论
Rik
Rik 2022-12-23
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
Robin 2022-12-23
移动:Image Analyst 2022-12-23
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
headValue = A(maxFlowrateRow, 1);
timeValue = A(maxFlowrateRow, 3);
% Print the results
fprintf('Head value: %d, flowrate: %.4f, time: %.4f\n', headValue, maxFlowrate, timeValue);
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.

更多回答(1 个)

Image Analyst
Image Analyst 2022-12-23
I am not seeing that in column 1. I see
fileName = 'SCURVE.xlsx';
data = readtable(fileName);
head(data)
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

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by