Created
July 20, 2010 00:19
-
-
Save jfhbrook/482251 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% datamanip_example.m | |
% An example for Kyle | |
% Example vectors | |
a=1:10 | |
b=11:20 | |
% Probably the format you'll see them in: | |
A= [a' b'] | |
% Let's stack b like 20 times: | |
bprime=[]; | |
for i=1:20, | |
% Shoves b' onto the end of bprime 20 times | |
bprime=[ bprime; b' ]; | |
end | |
% Now, we can make a new A: | |
Aprime=[(1:length(bprime))' bprime ] | |
% (same deal as what we did before, with A=[a' b']) | |
% and now we can see what that would look like: | |
plot(Aprime(:,1),Aprime(:,2)); | |
%It should look like a sawtooth. | |
% Here's printing it out to csv: | |
% the "w" means "overwrite." See "help fopen" for more on that. | |
outputs = fopen('output.csv', 'w'); | |
% fprintf writes to file | |
fprintf(outputs,'# time, Temperature\n'); | |
% Loop through the rows | |
for i=1:size(Aprime,1), | |
%fprintf uses C-style formatting. See "help fprintf" for more on that. | |
fprintf(outputs, '%6.4f, %6.4f\n', Aprime(i,1), Aprime(i,2)); | |
end | |
% Might as well close our file like cool people do. | |
fclose(outputs); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
constructing multi-period data from a single period, and then writing it to a CSV in matlab. It seems matlab doesn't have a csv module! bummer. :(