Question

In: Computer Science

MATLAB ONLY please. Please put the entire code below. 1. you will read a list of...

MATLAB ONLY please. Please put the entire code below.

1. you will read a list of internet logs from a notepad.
2. then you will extract the following.
- a host (e.g., '146.204.224.152')
- a user_name (e.g., 'feest6811' note: sometimes the username is missing! In this case, use '-' as the value for the username.)
- the timme a request was made (e.g., '21/Jun/2019:15:45:24-0700')
- the post request type (e.g., 'POST /incentivize HTTP/1.1' note: not everthing is a POST!)

Your task is to convert this into a list of strings:
"host :146.204.224.152"
"user_name: feest6811",
"time :21/Jun/2019:15:45:24 -0700",
"request: POST /incentivize HTTP/1.1' note: not everthing is a POST!)

LIST OF LOG FILES:

146.204.224.152 - feest6811 [21/Jun/2019:15:45:24 -0700] "POST /incentivize HTTP/1.1" 302 4622
197.109.77.178 - kertzmann3129 [21/Jun/2019:15:45:25 -0700] "DELETE /virtual/solutions/target/web+services HTTP/2.0" 203 26554
156.127.178.177 - okuneva5222 [21/Jun/2019:15:45:27 -0700] "DELETE /interactive/transparent/niches/revolutionize HTTP/1.1" 416 14701
100.32.205.59 - ortiz8891 [21/Jun/2019:15:45:28 -0700] "PATCH /architectures HTTP/1.0" 204 6048
168.95.156.240 - stark2413 [21/Jun/2019:15:45:31 -0700] "GET /engage HTTP/2.0" 201 9645
71.172.239.195 - dooley1853 [21/Jun/2019:15:45:32 -0700] "PUT /cutting-edge HTTP/2.0" 406 24498

Solutions

Expert Solution

The possible solutions for the given question:

a) if the file has table like structure use the following:

data = readtable('yourfilename.log')

b) if you want the output as an array:

data = dlmread('yourfilename.log')

c) For a table like structure of data

Str = fileread('yourfilename.log');

Key = 'it,it-nin,icytot,nrep2,mtfail,IMPES:';

Index = strfind(Str,Key);

Value =sscanf(Str(Index(1)+length(Key):end),'%g',1);

==========================================================

The solution for query:

You can import the mixed type of data as a cell array using the “readcell” function with “detectImportOptions” or the “textscan” function.

Code for the same:

a) The import using the “detectImportOptions” function;

opts = detectImportOptions('filename.txt'); % creating an import options object for the file %using the detectImportOptions function

opts.DataLines = [3 8]; % location of the data

C = readcell('filename.txt',opts); % import operation

b) The import using the textscan function;

N = 6; % specifying the size of block

formatSpec = '%D %f %f %f %c'; % formats of the data

% '%s' for text variables, '%D' for date and time variables, or '%c' for categorical variables.

fileID = fopen('bigfile.txt'); % open the file

C_first = textscan (fileID,formatSpec,N,'CommentStyle','##','Delimiter','\t') % Read the first block

C_first{3} %example

N = 7; % Updating the block size N

C_second = textscan (fileID,formatSpec,N,'CommentStyle','##','Delimiter','\t') % reading the second block

C_second{5} % example

fclose(fileID); % Closing the file.


Related Solutions

(MATLAB ONLY) (MATLAB ONLY) (MATLAB ONLY) (MATLAB ONLY) (MATLAB ONLY) (MATLAB ONLY) Please complete the following...
(MATLAB ONLY) (MATLAB ONLY) (MATLAB ONLY) (MATLAB ONLY) (MATLAB ONLY) (MATLAB ONLY) Please complete the following Question in MATLAB ASAP, Thanks. :) 2a. Write a function that outputs the amount of freezing point depression (in degrees C) given a mass of magnesium chloride salt and a volume of water. Formula to calculate freezing point depression: ΔT = iKm in which ΔT is the change in temperature in °C, i is the van't Hoff factor, which = 3 for MgCl2 because...
Answer please the Question below - in WRITTEN FORM ONLY PLEASE 1) Mr JM Hamdan put...
Answer please the Question below - in WRITTEN FORM ONLY PLEASE 1) Mr JM Hamdan put all his money in one stock, and the stock doubled in value in a matter of months. He did this three times in a row with three different stocks. J. M. got his picture on the front page of Khaleej Times. However, the paper never mentioned the thousands of investors who made similar bets on other stocks and lost most of their money. Explain...
Please, read the code below so you can figure out what is the steps that are...
Please, read the code below so you can figure out what is the steps that are used. (Answer in words) import java.util.*; import java.io.*; / class WordHelper{ public static String vowels = "aeiouyAEIOUY";    //method to check whether a given character is vowel or not public static String[] sortByVowels(String[] words){ Integer[] noOfVowels = new Integer[words.length]; String[] newArray = new String[words.length];    newArray[i] = words[i]; int cnt = 0; for(int j = 0; j < words[i].length(); j++){ String temp = Character.toString(words[i].charAt(j));...
the language is matlab 1) Write a code that will print a list consisting of “triangle,”...
the language is matlab 1) Write a code that will print a list consisting of “triangle,” “circle,” and “square.” It prompts the user to choose one, and then prompts the user for the appropriate quantities (e.g., the radius of the circle) and then prints its area. If the user enters an invalid choice, the script simply prints an error message. For calculating the area, create separate functions for each choice. Name them as calcTriangle, calcCircle, calcSquare respectively, which are only...
Code an Entire Piston Design in MATLAB or C with the given input parameters are Crank...
Code an Entire Piston Design in MATLAB or C with the given input parameters are Crank Length , crank radius, crank angle , maximum explosion pressure (Pmax) , bore , stroke Assume any for necessary values to get the output The output should include Piston clearance Top Skirt bottom Skirt crown thickness skirt thickness piston ring dimensions gudegeon pin dimensions
Fill in the blanks in the MATLAB code below.
Fill in the blanks in the MATLAB code below. (Do not type unnecessary words or blank spaces in your response. The correct answers are case-sensitive.) % Consider a row vector v. % Complete the lines of code below to find the average and standard deviation of the elements of vector v such that these two values are assigned to variables M and S, respectively. E = G =
This is a Matlab Exercise problem. Please create the Matlab code and figure for the following...
This is a Matlab Exercise problem. Please create the Matlab code and figure for the following problem using problem specifications: Plot x vs y when y=sin(x), y=cos(x), y=sin (2*x), and y=2*sin(x) when x = 1:0.1:10. Use 2 by 2 subplot, sin(x) is in location 1, cos(x) is in location 2, sin(2*x) is in location 3 and 2*sin(x) is in location 4. The plot should have: (1) x label = ‘x value’, y label = ‘y value’, legend ‘y=sin(x)’,’ y=cos(x)’,’ y=sin...
(only matlab code please) solve and plot the relation between the position vs time where m1=...
(only matlab code please) solve and plot the relation between the position vs time where m1= 1 kg , m2 = 1.5 kg (Mass) k1= 100 N/m , k2 = 125 N/m (spring) b = 1 (damper) Initial conditions: y1(0) =0.15 m , y ’1(0) =0.05 m/s y2(0) =0.05 m , y ’2(0) =0.03 m/s U1(t) = unit step starting at t (step time) = 0 sec U2 = u (t,5) (t (step time) = 5 sec) t = linspace(0,25)...
Please show MATLAB code to plot below function from x = −3 to x = 12:...
Please show MATLAB code to plot below function from x = −3 to x = 12: function f = piecewise(x) % implements piecewise function using if statements if x < 0     f = -x^3 - 2*x^2 + 3*x; elseif x <= 8     f = (12/pi) * sin(pi*x/4); else     f = (600*exp(x-8))/(7*(14 + 6*exp(x-8))) -30/7; end
please let me know reference of this MATLAB code. please explain this code line by line....
please let me know reference of this MATLAB code. please explain this code line by line. . . N=256; %% sampling number n=linspace(0,1,N); fs=1/(n(2)-n(1)); x=5*(sin((2*pi*10*n))); %% create signal N=length(x); f=[-fs/2:fs/N:fs/2-fs/N]; subplot(211) plot(f,fftshift(abs(fft(x)))); title('|G(f)|');grid; xlabel('frequency'); ylabel('|G(f)|'); %Zero padding xx=[zeros(1,128) x zeros(1,128)]; N=length(xx); f=[-fs/2:fs/N:fs/2-fs/N]; subplot(212) plot(f,fftshift(abs(fft(xx)))); title('|Gz(f)|');grid; xlabel('frequency'); ylabel('|Gz(f)|');
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT