could someone show me what the script file should look like for opening a file f
ID: 3831149 • Letter: C
Question
could someone show me what the script file should look like for opening a file for writing and how the rest of the problem should be done?
2. Write a script which will now use the fopen and fscanf to pull in the data into Matlab Open the files for reading Read in the data from Temp1.dat and stores it to a variable using fscanf Read in the data from Temp2.dat and stores it to a variable using fscanf Read in the data from Temp3.dat and stores it to a variable using fscanf Open the file for writing Write the data from Temp1.dat to the file Temperature.dat using fprintf Write the data from Temp2.dat to the file Temperature.dat using fprintf Write the data from Temp3.dat to the file Temperature.dat using fprintf Close the filesExplanation / Answer
Actually the syntax for writing is in reverse order in your code .
I'm providing the code from temp onwards :
temp=fopen('Temperature.dat','w');
fprintf(temp,'%-5.2f ',t1);
fprintf(temp,'%-5.2f ',t2);
fprintf(temp,'-%5.2f ',t3);
fclose(temp);
fclose(fid1);
fclose(fid2);
fclose(fid3);
The thing is after opening the file ,for fprintf method the first argument is to be the file handle/ID followed by format of text you want to write and finally providing the data corresponding to that format.
But in your code you are printing the existing data ..hope i answered your query.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.