Using the function command to open a .txt file
이전 댓글 표시
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
채택된 답변
추가 답변 (1개)
카테고리
도움말 센터 및 File Exchange에서 Performance and Memory에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!