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

Create a hierarchy of folders and files by using matlab the code for i=1:n Name=

ID: 3883629 • Letter: C

Question

Create a hierarchy of folders and files

by using matlab

the code

for i=1:n
Name=['dir',num2str(i)];
mkdir(Name);
for j=1:m
M = magic(7);
Name1=['file',num2str(j),'.txt'];
dlmwrite([Name,'',Name1],M,'-');
end
end

Current Folder file7.txt × + Name 1 30-39-48-1-10-19-28 2 38-47-7-9-18-27-29 3 46-6-8-17-26-35-37 4 5-14-16-25-34-36-45 5 13-15-24-33-42-44-4 6 21-23-32-41-43-3-12 7 22-31-40-49-2-11-20 file 1.txt file2.txt file3.tt file 1.txt file2.txt file3.tct file1.txt file2.txt file3.txt file 1.txt file2.txt file3.txt file1.txt file2.tt file3.txt 5420 2974-12 1753 23-23 1863 -12-319 5344 8-1-420 47-6234 3464123 e086-312 fil 3345122 1234567

Explanation / Answer

%Matlab program to create hierarchy of files and folders

n=input(' Enter the maximum number of directories:'); % input 'n' the number of directories to create
m = input(' Enter the maximum number of files:'); % input 'm' the number of files to create in each directory

% loop to create directories

for i=1:n
dir_name=strcat('dir',num2str(i)); % initializing dir_name variable with the required name of the directory
mkdir(dir_name); % creating directories

% loop to create files in the directories
for j=1:m
file_name = strcat('file',num2str(j),'.txt');  % initializing file_name variable with the required name of the file
filename = fullfile(dir_name,file_name); % buildng full filename u.e directory name + file name
file = fopen(filename,'w'); %opening the file in write mode
dlmwrite(filename,magic(j),'delimiter','-'); % write matrix magic(j) to ASCII-delimited file with delimiter '-'    fclose(file); % close the file

end

end

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