write output to a .txt or .mat file
12 views (last 30 days)
Show older comments
Hi everyone!
I have a couple of huge data files in .txt format and I´m creating 15-min intervals for these files so that each huge file gets reduced to a size of 34x42. The data files have the following structure:
datetime name price1 price2 price3 up to price40
19.10.09 09:00:00 basf 30 35 33 .....
19.10.09 09:15:00 basf 30 35 33 .....
19.10.09 09:30:00 basf 30 35 33 .....
19.10.09 09:45:00 basf 30 35 33 .....
...
19.10.09 17:30:00 basf 30 35 33 .....
My first question is how can I save such a file structure into a .txt or .mat file? because date and name are strings, and all prices are doubles. How can I put all this together? I thought of using a cell array but Im not sure because I´m really new to matlab and I´m learning it by doing. Also I tried:
save myvariables.txt datetime name price1 price2 price3
but it wont work because datetime and name are strings a nd the prices are doubles.
I also tried this:
save myvariables.txt price1 price2 price3
but the problem is that when i load it, the variables are loaded into my workspace as single variables and I can´t see thefile as the structure I mentioned above. How can i do it then?
So my second question is, , how could I save all these reduced files into a single .txt file or .mat file?? what kind of loop can I use to append all these reduced files into one single file?
I would really appreciate any help because I don´t know what else to do !
Thank you so much for your help :) Have a nice week!
Lourdes
0 Comments
Answers (3)
Ivan van der Kroon
on 17 May 2011
If you save and reload your data with
y=load();
you have a structure file anyhow. If you want to save your variables in time1.mat
save('time1.mat','datetime','name','price*');
(the * after price will save all the variables that start with price in their name, the so-called wildcard). If you now type
time1=load('time1.mat')
time1 =
price1: 30
price2: 35
price3: 33
name: 'basf'
datetime: '19.10.09 09:00:00'
Is this what your are looking for? If you might wonder how to implement this in a for-loop such that the number in 'time#.mat' goes up, you can use eval, as in
eval(['save(''time' num2str(k) '.mat'',''datetime'',''name'',''price*'');'])
where k is the number you want to assign to the mat-file. The double '' are to hold them inside the string class which eval requires in this case.
Furthermore, I would suggest to concatenate the prices in a single variable, i.e. price=[price1 price2 price3... ]. Just suggesting...
Ivan van der Kroon
on 18 May 2011
m=34;
n=42;
N=205;
A=zeros(m*N,42);
for j=1:N
%load matrix B, don't know how you saved it, so just assuming you do it here and have variable B of size 34x42.
A((j-1)*n+(1:n),:)=B;
end
0 Comments
See Also
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!