Using the function command to open a .txt file
Show older comments
The instruction on our homework was;
First Part
Accept the values n and m ( n - number of floors and m - number of apartments on each floor) the from the user and define appropriate size array to hold the number of mail items each resident has. Fill the array with random integer number in the range of 0 to 9.
Second part (I am currently stuck)
Write a function which will read the above file and determine the total mail items in the mailbox. Make sure to close the file before you leave the function. Call the function and print the result.
I think I am misunderstanding how the function command works, here is what I have;
m=input('Number of floors of the building: \n ');
n=input('Number of apartments per floor: \n');
array_mail=randi([0 9],n,m);
ave=mean(array_mail,'all');
fprintf('The average mail recieved by residents is: %4.0f\n',ave)
writematrix(array_mail,'perez_jethro_mailbox.txt')
function total_mail=AllMail('perez_jethro_mailbox.txt')
q = dlmread('perez_jethro_mailbox.txt')
total_mail = sum(q);
end
thanks for all the help
Accepted Answer
More Answers (1)
Jethro Perez
on 1 Dec 2020
0 votes
Categories
Find more on Performance and Memory in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!