Plot values of matching string

5 vues (au cours des 30 derniers jours)
pavan nittala
pavan nittala le 10 Juil 2019
Hi ,
I am running memory analysis test every 10sec on my Linux board and I need to plot the values of Usage of a certain process .
For Ex : , in the attached testme.txt , I need to search for string "Webkit" and get the Uss used by Webkit and plot them
In the given test file , it would be equivalent to plotting [88416, 27927] . Please note that the extra K needs to be eliminated

Réponses (1)

Sameer
Sameer le 7 Nov 2024
Here's a sample script to extract the necessary data as per you requirement, and plot it:
% Read the contents of the text file
filename = 'testme.txt'; % Replace with your actual file path
fileContent = fileread(filename);
% Use a regular expression to find the lines with "Webkit" and extract the Uss values
pattern = '\s*\d+\s+\d+K\s+\d+K\s+\d+K\s+(\d+)K\s+Webkit';
matches = regexp(fileContent, pattern, 'tokens');
% Convert the extracted values from strings to numbers
ussValues = cellfun(@(x) str2double(x{1}), matches);
% Plot the values
figure;
plot(ussValues, '-o');
title('Uss Usage of Webkit Process');
xlabel('Sample Number');
ylabel('Uss (KB)');
grid on;
Please refer to the below MathWorks documentation link:
Hope this helps!

Catégories

En savoir plus sur Characters and Strings 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!

Translated by