write output to a .txt or .mat file
조회 수: 5 (최근 30일)
이전 댓글 표시
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
답변 (3개)
Ivan van der Kroon
2011년 5월 17일
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
2011년 5월 18일
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
참고 항목
카테고리
Help Center 및 File Exchange에서 Entering Commands에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!