How do I open a new file for writing?

4 views (last 30 days)
I've already created the code needed for this part:
%Part A
clear all; clc;
tempdata = fopen('rec0506a.dat','r') ;
fgetl(tempdata);
fgetl(tempdata);
T = fscanf(tempdata, '%*f%f%f%f ',[3,inf])';
fclose(tempdata);
%Part B (means)
clc;
format shortg
sensormean= mean(T) ;
hourlymean = mean(T')' ;
%Part C (Table)
clc;
overallmean = (mean(sensormean) + mean(hourlymean))./2;
t = 1:8;
fprintf('hour T1 T2 T3 | means \n------------------------------------------------- \n')
fprintf('%2d %5d %4d %1d | %4.1f \n',[t',T,hourlymean]')
fprintf('--------------------------------------------------- \n')
fprintf('means = %2.1f %8.1f %7.1f | %6.1f \n',[sensormean,overallmean]')
How exactly do I do this part though? It's confusing me.
D) Open a new file for writing, say rec0506b.dat. Using again at most five fprintf commands, save the above table of Part (c) in the new file, then close the file and upload it on sakai together with the rest of your recitation work.

Accepted Answer

Gareth Thomas
Gareth Thomas on 25 Oct 2015
See: fopen
try using: fopen with 'w' instead of 'r'

More Answers (0)

Categories

Find more on Environment and Settings 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!