Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Any help would be appreciated!! This is in Matlab. You are given three text data

ID: 3779203 • Letter: A

Question

Any help would be appreciated!! This is in Matlab.

You are given three text data files (botanical.txt,playmakers.txt, andwell.txt) with this assignment. These will be in the same directory as your soltution.m file. Make sure that no other files with suffix ‘.txt’ are contained within this directory as otherwise the test will not pass. Create a function function [fileNames] = getFiles( fileFilter ) which takes a string fileFilter as an input and returns a cell array of file names as its output. The string fileFilter indicates the files you are interested in. By specifying ‘*.txt’ as input argument the function should return all filenames with suffix ‘.txt’ in the current directory. Hint: matlab’s command dir ( >> help dir ) implements most of the functionality needed for this sub-problem. Executing d = dir( fileFilter ); will return a structure ‘d’ containing the sought for file information. Simply select the file names from the structure, store them in a cell array and return this cell array as the output of getFiles. Write a statement in the solution file which determines all .txt files in the directory using this function and assign the result to the variable fileNames.

Explanation / Answer

THE MATLAB FUNCTION getFiles.m

function [ FileNames ] = getFiles(fileFilter)
% Function to filter txt files in a directory
d = dir(fileFilter); % filtering the files with .txt extension
for i=1:size(d) % size(d) will return the number of txt files
    FileNames{i} = d(i).name;% seperating the name of files from struct array
end
end


OUTPUT

>> A=getFiles('*.txt')

A =

    'andwell.txt'    'botanical.txt'    'playmarkers.txt'

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote