Plot values of matching string

5 ビュー (過去 30 日間)
pavan nittala
pavan nittala 2019 年 7 月 10 日
回答済み: Sameer 2024 年 11 月 7 日 9:28
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 日 9:28
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 Center および File ExchangeDescriptive Statistics についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by