Plot values of matching string

조회 수: 4 (최근 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 CenterFile Exchange에서 Descriptive Statistics에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by