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?
조회 수: 3 (최근 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
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
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.
댓글 수: 0
추가 답변 (1개)
Image Analyst
2022년 12월 23일
I am not seeing that in column 1. I see
fileName = 'SCURVE.xlsx';
data = readtable(fileName);
head(data)
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
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrices and Arrays에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!