Need guidance: Extracting variable and values from log file
Ältere Kommentare anzeigen
Hi,
I have a log file with three different algorithms time elapsed data along with number of users for each run. I have tried different methods but I am not able to exactly copy the data in a different variables. Kindly guide me where I am doing mistake?
Also guide me how I can automatically extract variables by matching the strings? I am using this question under this weblink as guideline.
https://se.mathworks.com/matlabcentral/answers/196440-how-to-find-a-particular-string-in-a-text-file
fclose('all')
clear all
%% ========================
fid=fopen('Simulation_Results.txt');
% This file contains variable names and variable values
values = textscan(fid, '%s', 'delimiter','\t','MultipleDelimsAsOne',1) ;

fclose(fid)
%% ========================
all_variable = values{1,1};
len= length(values{1,1});
for i = 2:2:len
numUser{i}= all_variable{i, 1};
%numUsr(i) = cell2mat(numUser(i));%% giving error
end
%% ========================
for j = 1:6:len
Time_Alg1{j}= all_variable{j, 1};
%Time_A1(i) = cell2mat(Time_Alg1(i));%% giving error
end
for k= 3:6:len
Time_Alg2{k}= all_variable{k, 1};
%Time_A2(i) = cell2mat(Time_Alg2(i)); %% giving error
end
for l = 5:6:len
Time_Alg3{l}= all_variable{l, 1};
%Time_A3(i) = cell2mat(Time_Alg3(i));%% giving error
end
%% ========================
%%% ================================ Log File Snippet =================
Time Elapsed Algorithm 1: 0.226373
Num of Users: 9
Time Elapsed Algorithm 2: 0.301075
Num of Users: 9
Time Elapsed Algorithm 3: 0.302607
Num of Users: 9
Time Elapsed Algorithm 1: 0.543193
Num of Users: 18
Time Elapsed Algorithm 2: 0.571813
Num of Users: 18
Time Elapsed Algorithm 3: 0.813169
Num of Users: 18
Time Elapsed Algorithm 1: 1.07906
Num of Users: 27
Time Elapsed Algorithm 2: 1.05138
Num of Users: 27
Time Elapsed Algorithm 3: 0.999459
Num of Users: 27
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu String Parsing finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

