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 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
muhammad choudhry
le 23 Déc 2022
Réponse apportée : Image Analyst
le 23 Déc 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.
Thanks in advance for help
1 commentaire
Rik
le 23 Déc 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?
Réponse acceptée
Robin
le 23 Déc 2022
Déplacé(e) : Image Analyst
le 23 Déc 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
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 commentaires
Plus de réponses (1)
Image Analyst
le 23 Déc 2022
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 commentaires
Voir également
Catégories
En savoir plus sur Matrices and Arrays dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!