Plot values of matching string

4 次查看(过去 30 天)
pavan nittala
pavan nittala 2019-7-10
回答: Sameer 2024-11-7
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

回答(1 个)

Sameer
Sameer 2024-11-7
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!

类别

Help CenterFile Exchange 中查找有关 Characters and Strings 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by