How to find the value in one column based on a value of a another column.

10 vues (au cours des 30 derniers jours)
Joshua Krantz
Joshua Krantz le 24 Août 2022
Réponse apportée : Matt J le 5 Juil 2023
Hello,
I have a table with time being the first column and Pressure A, B, and C being columns 2-4. I would like to find a way to display the time it takes for the first instance of Pressure A, B and C (which occur at different times) to show a value greater than .6.
Any help is greatly appreciated, I have just started using matlab and am quite confused.
  1 commentaire
pragnan nadimatla
pragnan nadimatla le 5 Juil 2023
As per my understanding you want to find the values of one column (time) based on pressure values which are on other columns when certain threshold has been crossed.
Here’s an example of how to code :
% Generate example data
time = (0:0.1:1)';
pressureA = sin(2*pi*time);
pressureB = cos(2*pi*time);
pressureC = sin(4*pi*time);
% Combine data into a table
data = table(time, pressureA, pressureB, pressureC);
% Find the time it takes for each pressure to exceed 0.6
threshold = 0.6;
timeA = data.time(find(data.pressureA > threshold, 1));
timeB = data.time(find(data.pressureB > threshold, 1));
timeC = data.time(find(data.pressureC > threshold, 1));
% Display the results
disp(['Time for Pressure A to exceed ' num2str(threshold) ': ' num2str(timeA)]);
disp(['Time for Pressure B to exceed ' num2str(threshold) ': ' num2str(timeB)]);
disp(['Time for Pressure C to exceed ' num2str(threshold) ': ' num2str(timeC)]);
I have create a table using time and 3 pressure columns A,B,C and I have used matlab inbuilt function find inorder to find the exact time after the value has crossed certain threshold which is 0.6 in this case.I hope it resolves your query.

Connectez-vous pour commenter.

Réponses (1)

Matt J
Matt J le 5 Juil 2023
% Generate example data
time = (0:0.1:1)';
pressureA = 20*sin(time/3);
pressureB = 20*sin(pi*time/4);
pressureC = 20*sin(pi*time/5);
% Combine data into a table
data = table(time, pressureA, pressureB, pressureC)
data = 11×4 table
time pressureA pressureB pressureC ____ _________ _________ _________ 0 0 0 0 0.1 0.66654 1.5692 1.2558 0.2 1.3323 3.1287 2.5067 0.3 1.9967 4.6689 3.7476 0.4 2.6588 6.1803 4.9738 0.5 3.3179 7.6537 6.1803 0.6 3.9734 9.0798 7.3625 0.7 4.6244 10.45 8.5156 0.8 5.2703 11.756 9.6351 0.9 5.9104 12.989 10.717 1 6.5439 14.142 11.756
[~,i]=max(data{:,2:end}>6);
result = time(i)'
result = 1×3
1.0000 0.4000 0.5000

Catégories

En savoir plus sur Workspace Variables and MAT-Files dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by