How do I open a new file for writing?

4 vues (au cours des 30 derniers jours)
Ruten9
Ruten9 le 25 Oct 2015
Modifié(e) : per isakson le 10 Nov 2015
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.

Réponse acceptée

Gareth Thomas
Gareth Thomas le 25 Oct 2015
See: fopen
try using: fopen with 'w' instead of 'r'
  1 commentaire
Ruten9
Ruten9 le 25 Oct 2015
I figured that already. Thanks though!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Environment and Settings dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by