From: Wayne King on 18 Jun 2010 09:54 "Benedikt Heudorfer" <rawker_(a)web.de> wrote in message <hvfsq0$irc$1(a)fred.mathworks.com>... > "Wayne King" <wmkingty(a)gmail.com> wrote in message <hvfpko$q1b$1(a)fred.mathworks.com>... > > "Benedikt Heudorfer" <rawker_(a)web.de> wrote in message <hvfo0n$eu4$1(a)fred.mathworks.com>... > > > my script is the following: > > > > > > > > > > > > clear all; > > > fid = fopen('Q_HK_Bechernbach.txt','r'); > > > file = textscan(fid, '%f %17c %f %f','headerLines', 1, 'Delimiter',','); > > > date=datenum(file{2}, 'dd.mm.yyyy HH:MM'); > > > > > > lgt=length(date); > > > work(:,1)=file{1,4}*0.001; > > > > > > % generate daily timeserie > > > stime=floor(date(1)); > > > etime=floor(date(lgt)); > > > difftime=etime-stime; > > > steps=difftime/1; > > > timeline=zeros(2,1); > > > timeline(1,1)=stime; > > > dummy=stime; > > > for i=2:steps+1 > > > timeline(i,1)=dummy+1; > > > dummy=timeline(i,1); > > > end > > > > > > % calculating daily values > > > lgt2=length(timeline); > > > results=zeros(lgt2,1); > > > for a=1:lgt2 > > > for i=1:lgt > > > if a<lgt2 > > > if date(i)>=timeline(a) && date(i)<timeline(a+1) > > > results(a,1)=results(a,1)+work(i,1); > > > end > > > else for b=1:lgt > > > if date(b)>=timeline(lgt2) > > > results(lgt2,1)=results(lgt2,1)+work(b,1); > > > end > > > end > > > end > > > end > > > end > > > > > > %fid=fopen('Bechernbach_Tageswerte.txt', 'w'); > > > %fprintf(fid,'%16d %f\n',date, results(:,1)); > > > %fclose(fid); > > > > > > > > > > > > everything works except the saving into .txt. (last 3 lines with the %...) > > > i want 2 columns: first with the date, second with data from results(:,1) > > > > Hi Benedikt, Without going through all your code in detail, I see you have a vector of serial date numbers and data, how about this: > > > > Form a 2xN matrix with the first row your date number and the second row your data > > > > x=1:10; y =1:10; > > z = [x;y]; > > fprintf('%3d\t %f\n',z); > > > > Obviously, you have to substitute in your code: > > > > % I'm assuming that date is a column vector > > > > Data = [date'; results(:,1)']; > > fid=fopen('Bechernbach_Tageswerte.txt', 'w'); > > fprintf(fid,'%16d\t %f\n', Data); > > fclose(fid); > > > > I think it should work without the \t escape character, so try it both ways. > > > > Wayne > > thank you very very much. > it partially helped. It does write values into a .txt now, but in a wrong order. with your script, i write: > > data = [date,results(:,1)]; > fid=fopen('Bechernbach_Tageswerte.txt', 'w'); > fprintf(fid,'%16d\t %f\n',data); > fclose(fid); > > Problem now: first it writes all dates in both column, and then below that all results in both columns. like this: > 733165 733166.000000 > 733167 733168.000000 > 733169 733170.000000 > 733171 733172.000000 > 733173 733174.000000 > ... > 734149 734150.000000 > 734151 734152.000000 > 2.970035e-02 0.118471 > 1.226650e-01 0.124119 > 1.258972e-01 0.381086 > > whats wrong now? Hi Benedikt, You did not follow my advice and make Data a matrix with two rows and N columns. Data = [date'; results(:,1)']; fid=fopen('Bechernbach_Tageswerte.txt', 'w'); fprintf(fid,'%16d\t %f\n', Data); fclose(fid); You made: data = [date,results(:,1)]; which is Nx2. You want your result to be 2xN. See my previous post. Replace your line: data = [date,results(:,1)]; with data = [date,results(:,1)]'; Wayne
From: Benedikt Heudorfer on 18 Jun 2010 10:12 Ok thanks to all of you, I didn't expect the ' are so important ;-) both dpd's and Wayne's suggestions worked, just the ' in different places... but i tried and did not get the thing with horzcat... nevertheless, thank you all Benedikt
First
|
Prev
|
Pages: 1 2 Prev: Stateflow Transition (MultiLine) Next: uiwait multiple figure interface |