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!