From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: fprintf() statements
Date: Tue, 30 Oct 2012 00:51:07 +0000 (UTC)
Organization: Ohio State University
Lines: 22
Message-ID: <k6n89r$sia$>
Reply-To: <HIDDEN>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: 1351558267 29258 (30 Oct 2012 00:51:07 GMT)
NNTP-Posting-Date: Tue, 30 Oct 2012 00:51:07 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 3351806
Xref: comp.soft-sys.matlab:781627


I am a teaching assistant for an engineering class, and one of my students submitted an assignment that contains fprintf() statements that are slightly different than what I am accustomed to seeing.

The students were to add '2' to every value in a file 'voltageout.txt'

clear all
%prompt user for filename
fprintf ('What is the filename?\n');
filename = input('filename = ','s');
%store data in file as vector 'voltages'
voltages = load(filename);
%prompt user for offset voltage
offset=input('Enter the offset voltage:\n');
%add offset to voltages
voltages = voltages + 2;
%save data in voltageoutplus2b.txt
save voltageoutplus2b.txt voltages -ascii
fprintf (1,'data has been saved to voltageoutplus2a.txt\n');

the part of this code that was unfamiliar to me was the '1' in the fprintf() statement. I am aware that that position is used for a file identifier; is there any other reason to put a '1' in that position? I also experimented a bit and found that if I replace the '1' with a '2', the string still displays to the command window, but is the color red. Thanks for the assistance!