this is sample yearly data (362 file data) (2.11m)
Sie verfolgen jetzt diese Frage
- Aktualisierungen können Sie in Ihrem Feed verfolgter Inhalte sehen.
- Je nach Ihren Kommunikationseinstellungen können Sie auch E-Mails erhalten.
how to make monthly graph from daily file data
6 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
thank to per isakson
from this code (daily/1 file) can u make monthly graph (30file data)?? =====
function RainData = ReadManySoniData( folder_name, file_spec )
sad = dir( fullfile( folder_name, file_spec ) );
RainData = struct([]);
for sa = transpose( sad )
RainData = cat( 2, RainData, ReadOneSoniData( folder_name, sa.name ) );
end
[ dummy, ixs ] = sort( [ RainData(:).DayNumber ] );
RainData = RainData( ixs );
end
function rain_data = ReadOneSoniData( folder_name, file_name )
fid = fopen( fullfile( folder_name, file_name ), 'r' );
if not( fid >= 3 )
error( 'ReadOneSoniData:NoFileFound' ...
, 'Cannot find file "%s"' ...
, fullfile( folder_name, file_name ) )
end
cac = textscan( fid, '%s', 'Whitespace','', 'Delimiter','\n' );
fclose( fid );
cac = cac{:};
tmp = cellfun( 'isempty' ...
, regexp( cac, '\d{2}:\d{2}:\d{2}\s+C\s*$' ) );
isc = not( tmp );
tmp = cellfun( 'isempty' ...
, regexp( cac, '\d{2}:\d{2}:\d{2}\s+\*\*\s+----' ) );
iss = not( tmp );
cac( isc | iss ) = [];
str = transpose( char( cac ) );
nl = sprintf('\n');
str = cat( 1, str, repmat( nl(:), [length(nl),size(str,2)] ) );
cac = cell(1,9);
[cac{:}] = strread( str, '%8c%2c%4f%7f%4c%4u%4u%4u+%2u' ...
, 'delimiter', ' ', 'whitespace', '' );
try
date_vec = nan(1,3);
date_vec( [2,3,1] ) = sscanf( file_name, '%2u-%2u-%4u%*s' );
catch me
if strcmp( me.identifier, 'MATLAB:index_assign_element_count_mismatch' )
warning( 'ReadOneSoniData:CannotParseFileName' ...
, 'Cannot extract a date from file name: "%s"' ...
, file_name )
rain_data = struct([]);
return
else
rethrow( me )
end
end
str = transpose( char( cac{1} ) );
vec = nan( size(str,2), 3 );
[ vec(:,1), vec(:,2), vec(:,3) ] ...
= strread( str, '%2u:%2u:%2u', 'delimiter','','whitespace','' );
rain_data.Created = datestr( now, 'yyyy-mm-dd HH:MM:SS' );
rain_data.DataFile = fullfile( folder_name, file_name );
rain_data.Datevec = [ repmat( date_vec, [size(vec,1),1] ), vec ];
rain_data.DayNumber = datenum( date_vec );
rain_data.Rain = cac{3};
rain_data.DailyRain = sum( rain_data.Rain );
% and more as you see fit.
end
2 Kommentare
Soni huu
am 6 Jul. 2012
⋮
-
Verknüpfen
Direkter Link zu diesem Kommentar
Bearbeitet: Soni huu
am 6 Jul. 2012
per isakson
am 6 Jul. 2012
⋮
-
Verknüpfen
Direkter Link zu diesem Kommentar
"from this code (daily/1 file) can u make monthly graph (30file data)??"
Put more effort in describing what you need!
Akzeptierte Antwort
per isakson
am 6 Jul. 2012
Bearbeitet: per isakson
am 6 Jul. 2012
Here is a function that returns total monthly rain. Try
>> mr = MonthlyRain( RainData );
>> plot( mr(1).Rain, 'd' );
>> bar( mr.Rain );
The values of the monthly rain could they be correct?
function monthly_rain = MonthlyRain( RainData )
day_number = [ RainData(:).DayNumber ];
month_number= month( day_number );
year_number = year( day_number );
year_list = unique( year_number );
monthly_rain = struct( 'Year', num2cell( year_list ), 'Rain', nan(12,1) );
ix_yy = 0;
for yy = year_list
is_yy = ( yy == year_number );
ix_yy = ix_yy + 1;
for mm = 1 : 12
is_mm = ( mm == month_number );
is_ym = ( is_yy & is_mm );
if any( is_ym )
monthly_rain(ix_yy).Rain(mm) = sum([RainData( is_ym ).DailyRain]);
end
end
end
end
63 Kommentare
Soni huu
am 6 Jul. 2012
⋮
-
Verknüpfen
Direkter Link zu diesem Kommentar
its work.. how about daily?? i just to make 12 folder, one folder to one month?
per isakson
am 6 Jul. 2012
⋮
-
Verknüpfen
Direkter Link zu diesem Kommentar
Bearbeitet: per isakson
am 6 Jul. 2012
Not needed! I'm worried about missing data and how that should be reported. In next version?
Soni huu
am 11 Jul. 2012
⋮
-
Verknüpfen
Direkter Link zu diesem Kommentar
> mr = MonthlyRain( RainData ); work
>> plot( mr(1).Rain, 'd' ); work
>> bar( mr.Rain ); not work for 2010 data, just 1 vertikal line..
per isakson
am 11 Jul. 2012
⋮
-
Verknüpfen
Direkter Link zu diesem Kommentar
Have you solved the problem with reading the 2010 data?
what does
[ mr.Rain ]
return?
Soni huu
am 12 Jul. 2012
⋮
-
Verknüpfen
Direkter Link zu diesem Kommentar
Bearbeitet: Soni huu
am 12 Jul. 2012
this code for monthlty data in a year.. u tell me b4 when i plot mountly data with mounth whit code :
[plot( mr(1).Rain, 'd' )]
its work,
n if i write
bar(mr.Rain).
the bar graph just show 1 bar graph.
per isakson
am 12 Jul. 2012
⋮
-
Verknüpfen
Direkter Link zu diesem Kommentar
Bearbeitet: per isakson
am 12 Jul. 2012
It's close to impossible for me to know what causes your problems. I made a bar graph at one point, which showed to bars.
I don't know what changes you made to the code. I don't try to keep my own version.
You avoid to answer to my questions. Thus, I repeat:
Have you solved the problem with reading the 2010 data?
what does
[ mr.Rain ]
return?
Soni huu
am 12 Jul. 2012
⋮
-
Verknüpfen
Direkter Link zu diesem Kommentar
yes.. i search error data with manual way... i found some line data just have 3 cell, 4 cell ect.. not 9 cell data.
u say; mr = MonthlyRain( RainData ); sorry i can understand with ur question "return"
per isakson
am 12 Jul. 2012
⋮
-
Verknüpfen
Direkter Link zu diesem Kommentar
Did you delete the short lines?
When you type
[ mr.Rain ]
in the command window what does matlab print in the command window?
Soni huu
am 12 Jul. 2012
⋮
-
Verknüpfen
Direkter Link zu diesem Kommentar
yea i delete the short line coz the instrument work in a half day.(ex 00-00 to 12:30, n the last data (12:30)just have 3 cell.)
in the command window what does matlab print in the command window? =
NaN
NaN
NaN
NaN
NaN
NaN
NaN
NaN
NaN
NaN
4.0540
NaN
Soni huu
am 12 Jul. 2012
⋮
-
Verknüpfen
Direkter Link zu diesem Kommentar
mr(1).Rain
ans =
184.0523
164.5246
302.7785
366.3460
229.8752
224.1105
103.3908
179.5921
191.0299
79.0037
219.1555
79.5646
Soni huu
am 12 Jul. 2012
⋮
-
Verknüpfen
Direkter Link zu diesem Kommentar
Bearbeitet: Soni huu
am 12 Jul. 2012
amazing.... now i write
bar(mr(1).Rain)
but how we know every data is read the right data? (how to know) ?
per isakson
am 12 Jul. 2012
⋮
-
Verknüpfen
Direkter Link zu diesem Kommentar
Bearbeitet: per isakson
am 12 Jul. 2012
That is a really good question!
- inspect and understand the code
- test the code, e.g make a file with synthetic data for which you know the answers
- especially, you need to make tests with files with missing data
Goggle for "Testing software" :-) ... and there is always another bug!
per isakson
am 12 Jul. 2012
⋮
-
Verknüpfen
Direkter Link zu diesem Kommentar
Try
>> mr(ii).Year
The output below is that from the test file with a few days in november?
...
NaN
4.0540
NaN
per isakson
am 12 Jul. 2012
⋮
-
Verknüpfen
Direkter Link zu diesem Kommentar
"yea i delete the short line coz the instrument ..."
The problem with that is that next time you will also need to do it manually.
My comment per isakson on 10 Jul 2012 at 16:32
First step: In ReadManySoniData replace
....
aimed at an automatic solution.
Soni huu
am 12 Jul. 2012
⋮
-
Verknüpfen
Direkter Link zu diesem Kommentar
Bearbeitet: Soni huu
am 12 Jul. 2012
function RainData = ReadManySoniData( folder_name, file_spec )
sad = dir( fullfile( folder_name, file_spec ) );
RainData = struct([]);
for sa = transpose( sad )
for sa = transpose( sad )
try
RainData = cat(2,RainData,ReadOneSoniData(folder_name,sa.name)
catch
fprintf( 'Folder: %s\nFile: %s\n', foldername, sa.name )
disp( lasterr )
end
end
[ dummy, ixs ] = sort( [ RainData(:).DayNumber ] );
RainData = RainData( ixs );
end
Soni huu
am 12 Jul. 2012
⋮
-
Verknüpfen
Direkter Link zu diesem Kommentar
RainData = ReadManySoniData( 'C:\matlab7\work\org\2011', '*.dat' );
??? Error: File: C:\matlab7\work\org\ReadManySoniData.m Line: 5 Column: 11
Illegal use of reserved keyword "function".
per isakson
am 12 Jul. 2012
⋮
-
Verknüpfen
Direkter Link zu diesem Kommentar
Bearbeitet: per isakson
am 12 Jul. 2012
You missed "try"
...
for sa = transpose( sad )
try
RainData = cat(2,RainData,ReadOneSoniData(folder_name,sa.name);
catch
fprintf( 'Folder: %s\nFile: %s\n', foldername, sa.name )
disp( lasterr )
end
end
...
Soni huu
am 12 Jul. 2012
⋮
-
Verknüpfen
Direkter Link zu diesem Kommentar
with "try"
RainData = ReadManySoniData( 'C:\matlab7\work\org\2011', '*.dat' );
??? Error: File: C:\matlab7\work\org\ReadManySoniData.m Line: 7 Column: 71
Incomplete or misformed expression or statement.
per isakson
am 12 Jul. 2012
⋮
-
Verknüpfen
Direkter Link zu diesem Kommentar
Bearbeitet: per isakson
am 12 Jul. 2012
You know - not me - whats on line: 7 column: 71. Fix the line! I guess it is is a typing error.
Make sure the Code Analyzer box is green before you run the code.
Soni huu
am 12 Jul. 2012
⋮
-
Verknüpfen
Direkter Link zu diesem Kommentar
ok, its work now..
Soni huu
am 12 Jul. 2012
⋮
-
Verknüpfen
Direkter Link zu diesem Kommentar
Bearbeitet: Soni huu
am 12 Jul. 2012
if data is not error, the code is running
for error data (2010)
>> RainData = ReadManySoniData( 'C:\matlab7\work\org\2010', '*.dat' );
??? Undefined function or variable 'foldername'.
Error in ==> ReadManySoniData at 9
fprintf( 'Folder: %s\nFile: %s\n', foldername, sa.name )
per isakson
am 12 Jul. 2012
⋮
-
Verknüpfen
Direkter Link zu diesem Kommentar
Bearbeitet: per isakson
am 12 Jul. 2012
Replace
foldername
by
folder_name
.
The Code Analyzer box was it green before you run the code?
Soni huu
am 12 Jul. 2012
⋮
-
Verknüpfen
Direkter Link zu diesem Kommentar
dont read the error line
RainData = ReadManySoniData( 'C:\matlab7\work\org\2010', '*.dat' );
Folder: C:\matlab7\work\org\2010
File: 01-01-2010.dat
Trouble reading literal string from file (row 543, field 9) ==> \n
Folder: C:\matlab7\work\org\2010
File: 01-02-2010.dat
Trouble reading literal string from file (row 400, field 9) ==>
........
Error in ==> ReadManySoniData at 6
RainData = cat(2,RainData,ReadOneSoniData( folder_name, sa.name ));
Soni huu
am 12 Jul. 2012
⋮
-
Verknüpfen
Direkter Link zu diesem Kommentar
its ok if us this code?
else
fprinft(fidd,tline) ;
per isakson
am 12 Jul. 2012
⋮
-
Verknüpfen
Direkter Link zu diesem Kommentar
Bearbeitet: per isakson
am 12 Jul. 2012
Now you have a "list" of dat-files with lines that the code cannot read. These two steps remain:
Third step: Inspect the files (causing trouble) with an editor. Make a list with the lines, which you think are the cause of the trouble.
Fourth step: What do these lines have in common? How can these lines be identified? By what rule?
.
The message
Error in ==> ReadManySoniData at 6
RainData = cat(2,RainData,ReadOneSoniData( folder_name, sa.name ));
does not mean anything to me!
else
fprinft(fidd,tline) ;
I cannot guess what this is! There is a typing mistake in the name of the function.
Soni huu
am 12 Jul. 2012
⋮
-
Verknüpfen
Direkter Link zu diesem Kommentar
Bearbeitet: Soni huu
am 12 Jul. 2012
this the sample the error data, error data is in the last line in a file
06:59:00 ** ---- ---.--- 01** 0000 0000 00
in File: 01-01-2010.dat
06:39:00 .000 0
in File: 01-02-2010.dat
06:59:00 .000 019.142 01** 4862 0058 00
File: 01-03-2010.dat
06:39:00 .000 0
File: 01-04-2010.dat
06:39:00 .000 0
File: 01-06-2010.dat
the problem is. the data is not 9 cell.
per isakson
am 12 Jul. 2012
⋮
-
Verknüpfen
Direkter Link zu diesem Kommentar
"06:39:00" appears three times. Does that mean anything?
What rule would you propose for removing rows?
Soni huu
am 12 Jul. 2012
⋮
-
Verknüpfen
Direkter Link zu diesem Kommentar
Bearbeitet: Soni huu
am 12 Jul. 2012
11 error line data
there is a problem with the instrument.. every 06:39:00 the instrument is off for maintenence.. but just 9 line data like that in january(1 jan -9 jan). after that no anymore..
per isakson
am 12 Jul. 2012
⋮
-
Verknüpfen
Direkter Link zu diesem Kommentar
Bearbeitet: per isakson
am 12 Jul. 2012
What rule would you propose for removing rows?
.
This line should not have cause an error. It should have been removed by existing code. Thus, there is a problem.
06:59:00 ** ---- ---.--- 01** 0000 0000 00
in File: 01-01-2010.dat
Soni huu
am 12 Jul. 2012
⋮
-
Verknüpfen
Direkter Link zu diesem Kommentar
and the other error data is:
08:07:00 .000 000.430 01** 4860 0057 0058 +21
08:09:00 .000 000.430 01** 4862 0057 0058 +21
08:09:00 +21
08:10:00 .000 000.430 01** 4862 0057 0058 +21
08:11:00 .000 000.430 01** 4862 0057 0058 +22
Soni huu
am 12 Jul. 2012
⋮
-
Verknüpfen
Direkter Link zu diesem Kommentar
Bearbeitet: Soni huu
am 12 Jul. 2012
i just want the data if the cell is not 9 cell will not to be read.. coz maybe temperature (cell 9) will show in cell 3.. so the case like that will make the big mistake to read the data
Soni huu
am 12 Jul. 2012
⋮
-
Verknüpfen
Direkter Link zu diesem Kommentar
but the code still continiou to next code(step).. the data still valid?
per isakson
am 12 Jul. 2012
⋮
-
Verknüpfen
Direkter Link zu diesem Kommentar
Bearbeitet: per isakson
am 12 Jul. 2012
Why is these lines in error
08:10:00 .000 000.430 01** 4862 0057 0058 +21
08:11:00 .000 000.430 01** 4862 0057 0058 +22
I cannot see anything wrong in these lines!
.
"but the code still continiou to next code(step).. the data still valid?" I do not understand!
.
We have still not done
Fourth step: What do these lines have in common? How can these lines be identified? By what rule?
Soni huu
am 12 Jul. 2012
⋮
-
Verknüpfen
Direkter Link zu diesem Kommentar
Bearbeitet: Soni huu
am 12 Jul. 2012
no.. i just want to show you the data with the comparison, and i want to show you the error data is in the middle not in the last of file data.
08:09:00 .000 000.430 01** 4862 0057 0058 +21 % good
08:09:00 +21 % error (dont read)
08:10:00 .000 000.430 01** 4862 0057 0058 +21 % good
per isakson
am 12 Jul. 2012
⋮
-
Verknüpfen
Direkter Link zu diesem Kommentar
Bearbeitet: per isakson
am 12 Jul. 2012
Try to be more exact in your wording. Do not let me guess so much!
.
Add the following three lines to ReadSoniData.m
magic_length = 47; % ignore lines with length <= magic_length
is_row_too_short = cellfun( @(str) length(str) <= magic_length, cac);
cac( is_row_too_short ) = [];
.
between the two existing lines
cac( isc | iss ) = [];
and
str = transpose( char( cac ) );
.
This is drastic and may cause problems in the future. Do not forget that these lines are in the code.
Soni huu
am 12 Jul. 2012
⋮
-
Verknüpfen
Direkter Link zu diesem Kommentar
ok.. i fix it
Soni huu
am 13 Jul. 2012
⋮
-
Verknüpfen
Direkter Link zu diesem Kommentar
the code ignore all data. sorry my englis not good, i will try my best.
..............................
Function name must be a string.
Folder: C:\matlab7\work\org\2010
File: 12-31-2010.dat
Function name must be a string.
per isakson
am 13 Jul. 2012
⋮
-
Verknüpfen
Direkter Link zu diesem Kommentar
I cannot guess what is going on. I cannot see that anything in ReadOneSoniData.m could give that error message.
- Put a break point at the first line of ReadOneSoniData
- Start ReadManySoniData the same way that gave the error
- Step one line at a time
- Try to understand what happens; make notes
Which is the line of ReadOneSoniData that causes the error?
per isakson
am 13 Jul. 2012
⋮
-
Verknüpfen
Direkter Link zu diesem Kommentar
In ReadManySoniData replace
disp( lasterr )
by
le = lasterror;
disp( le.stack(1) )
disp( le.message )
That should provide a better message.
.
Run the function
>> rd = ReadManySoniData( 'C:\matlab7\work\org\2010', '12-31-2010.dat' )
Soni huu
am 13 Jul. 2012
⋮
-
Verknüpfen
Direkter Link zu diesem Kommentar
Bearbeitet: Soni huu
am 13 Jul. 2012
i think this code ignore the file name. (file name <= 47)
??? Input argument "folder_name" is undefined.
Error in ==> ReadOneSoniData at 2
fid = fopen( fullfile( folder_name, file_name ), 'r' );
per isakson
am 13 Jul. 2012
⋮
-
Verknüpfen
Direkter Link zu diesem Kommentar
This is another error!
- Put a break point on the first line of ReadManySoniData
- Step one line at a time
- For every step note the value of the variable, folder_name
per isakson
am 13 Jul. 2012
⋮
-
Verknüpfen
Direkter Link zu diesem Kommentar
Why do you think that "this code ignore the file name" when the message says:
??? Input argument "folder_name" is undefined.
? .
What do you mean by "file name <= 47)"?
Soni huu
am 13 Jul. 2012
⋮
-
Verknüpfen
Direkter Link zu diesem Kommentar
>> rd= ReadManySoniData( 'C:\matlab7\work\org\2010', '*.dat' );
Folder: C:\matlab7\work\org\2010
File: 01-01-2010.dat
??? Reference to non-existent field 'stack'.
Error in ==> ReadManySoniData at 11
disp( le.stack(1) )
per isakson
am 13 Jul. 2012
⋮
-
Verknüpfen
Direkter Link zu diesem Kommentar
Bearbeitet: per isakson
am 13 Jul. 2012
- Put a break point at the line
le = lasterror;
- Step one line
- Check carefully all the fields of the structure, le
I cannot test because I run R2012a. In the command window run
>> le=lasterror
le =
message: 'Undefined function or variable 'lastwarning'.'
identifier: 'MATLAB:UndefinedFunction'
stack: [0x1 struct]
Do you see other fields?
Soni huu
am 13 Jul. 2012
⋮
-
Verknüpfen
Direkter Link zu diesem Kommentar
magic_length = 47; % ignore lines with length <= magic_length
"01-01-2010.dat" (14 string) <= 47
but i think i was wrong
Soni huu
am 13 Jul. 2012
⋮
-
Verknüpfen
Direkter Link zu diesem Kommentar
le=lasterror
le =
le =
message: [1x46 char]
identifier: 'MATLAB:minrhs'
??? le = |
Error: Incomplete or misformed expression or statement.
per isakson
am 13 Jul. 2012
⋮
-
Verknüpfen
Direkter Link zu diesem Kommentar
This looks like a Matlab problem. Try
>> soni
Undefined function or variable 'soni'.
>> le=lasterror
le =
message: 'Undefined function or variable 'soni'.'
identifier: 'MATLAB:UndefinedFunction'
stack: [0x1 struct]
>>
per isakson
am 13 Jul. 2012
⋮
-
Verknüpfen
Direkter Link zu diesem Kommentar
In ReadManySoniData replace
disp( le.stack(1) )
disp( le.message )
by
disp( le.message )
disp( le.identifier )
disp( le.stack(1) )
per isakson
am 13 Jul. 2012
⋮
-
Verknüpfen
Direkter Link zu diesem Kommentar
Where does this come from?
??? le =
Have you typed
le = <return>
Soni huu
am 13 Jul. 2012
⋮
-
Verknüpfen
Direkter Link zu diesem Kommentar
>> RainData = ReadManySoniData( 'C:\matlab7\work\org\2010', '*.dat' );
Folder: C:\matlab7\work\org\2010
File: 01-01-2010.dat
Function name must be a string.
MATLAB:cellfun:InvalidFirstInput
??? Reference to non-existent field 'stack'.
Error in ==> ReadManySoniData at 14
disp( le.stack(1) )
Soni huu
am 13 Jul. 2012
⋮
-
Verknüpfen
Direkter Link zu diesem Kommentar
Bearbeitet: Soni huu
am 13 Jul. 2012
soni
??? Undefined function or variable 'soni'.
>> le=lasterror
le =
message: 'Undefined function or variable 'soni'.'
identifier: 'MATLAB:UndefinedFunction'
i dont see "stack"
per isakson
am 13 Jul. 2012
⋮
-
Verknüpfen
Direkter Link zu diesem Kommentar
Bearbeitet: per isakson
am 13 Jul. 2012
You have an old Matlab version :(
Comment out
% disp( le.stack(1) )
.
The question is: what line causes the error message
Function name must be a string.
Put a copy of the line
RainData = cat( 2, RainData, ReadOneSoniData(folder_name,sa.name) );
before the line
try
Run
>> rd = ReadManySoniData( 'C:\matlab7\work\org\2010', '01-01-2010.dat' );
Soni huu
am 13 Jul. 2012
⋮
-
Verknüpfen
Direkter Link zu diesem Kommentar
in 2 day i will have matlab 2012a... :D
per isakson
am 13 Jul. 2012
⋮
-
Verknüpfen
Direkter Link zu diesem Kommentar
Run ReadOneSoniData
>> ReadOneSoniData( 'C:\matlab7\work\org\2010', '01-01-2010.dat' )
Soni huu
am 13 Jul. 2012
⋮
-
Verknüpfen
Direkter Link zu diesem Kommentar
RainData = ReadManySoniData( 'C:\matlab7\work\org\2010', '*.dat' );
...............................
Folder: C:\matlab7\work\org\2010
File: 12-31-2010.dat
Function name must be a string.
MATLAB:cellfun:InvalidFirstInput
>> RainData = cat( 2, RainData, ReadOneSoniData(folder_name,sa.name) );
??? Undefined function or variable 'folder_name'.
Soni huu
am 13 Jul. 2012
⋮
-
Verknüpfen
Direkter Link zu diesem Kommentar
>> ReadOneSoniData( 'C:\matlab7\work\org\2010', '01-01-2010.dat' )
??? Function name must be a string.
Error in ==> ReadOneSoniData at 19
is_row_too_short = cellfun( @(str) length(str) <= magic_length, cac);
per isakson
am 13 Jul. 2012
⋮
-
Verknüpfen
Direkter Link zu diesem Kommentar
Bearbeitet: per isakson
am 13 Jul. 2012
In ReadOneSoniData replace
magic_length = 47; % ignore lines with length <= magic_length
is_row_too_short = cellfun( @(str) length(str) <= magic_length, cac);
cac( is_row_too_short ) = [];
by
magic_length = 47; % ignore lines with length <= magic_length
is_too_short = cellfun( 'length', cac ) <= magic_length;
cac( is_too_short ) = [];
and run
>> ReadOneSoniData( 'C:\matlab7\work\org\2010', '01-01-2010.dat' )
if successful run
>> RainData = ReadManySoniData( 'C:\matlab7\work\org\2010', '*.dat' );
Soni huu
am 13 Jul. 2012
⋮
-
Verknüpfen
Direkter Link zu diesem Kommentar
Bearbeitet: Soni huu
am 13 Jul. 2012
>> ReadOneSoniData( 'C:\matlab7\work\org\2010', '01-01-2010.dat' )
ans =
Created: '2012-07-14 01:44:17'
DataFile: 'C:\matlab7\work\org\2010\01-01-2010.dat'
Datevec: [542x6 double]
DayNumber: 734139
Rainrate: [542x1 double]
Rain: [542x1 double]
DailyRain: 0.2864
suhu: [542x1 double]
meansuhu: 19.5018
maxsuhu: 24
minsuhu: 18
>> RainData = ReadManySoniData( 'C:\matlab7\work\org\2010', '*.dat' );
>>
Soni huu
am 13 Jul. 2012
⋮
-
Verknüpfen
Direkter Link zu diesem Kommentar
Bearbeitet: Soni huu
am 13 Jul. 2012
ReadOneSoniData( 'C:\matlab7\work\org\2010', '12-19-2010.dat' )
??? Trouble reading literal string from file (row 2, field 9) ==> \n
Error in ==> strread at 51
[varargout{1:nlhs}]=dataread('string',varargin{:},'bufsize',2*num );
Error in ==> ReadOneSoniData at 25
[cac{:}] = strread( str, '%8c%2c%4f%7f%4c%4u%4u%4u+%2u' ...
the sample data;
per isakson
am 13 Jul. 2012
⋮
-
Verknüpfen
Direkter Link zu diesem Kommentar
Thus the code works. Do you think the value
DailyRain: 0.2864
is correct? Open the file, 01-01-2010.dat, in an editor and check.
Soni huu
am 13 Jul. 2012
⋮
-
Verknüpfen
Direkter Link zu diesem Kommentar
yes
DailyRain: 0.2864
but my sample is unique format (69kb)
per isakson
am 13 Jul. 2012
⋮
-
Verknüpfen
Direkter Link zu diesem Kommentar
Do you have problem reading the file, '12-19-2010.dat'?
I have successfully red the 2011 data, which I downloaded some days ago. However, I will not download more data. I've run out of time.
Add these lines
fid = fopen( 'c:\temp\ReadRainDataFailures.log', 'a' );
if fid >= 3
fprintf(fid, '%s | %s | %s\n',datestr(now),folder_name, sa.name );
fclose( fid );
end
after
% disp( le.stack(1) )
That will give you a list of the files, which cannot be red. You might want to change the name and folder of the file. Do you have a "c:\temp"?
If you run into specific problems try make a question at Answers.
Soni huu
am 13 Jul. 2012
⋮
-
Verknüpfen
Direkter Link zu diesem Kommentar
the code work now......... yes i have c:\temp
Weitere Antworten (1)
per isakson
am 6 Jul. 2012
Here is a function that collects total daily rain for one month at a time. Try
>> [ day_number, daily_rain ] = DailyRain( RainData, 2011, 11 );
>> plot( day_number, daily_rain )
>> figure, plot( day_number, daily_rain, '.' )
>> figure, plot( day_number, '.' )
As is and all that! You must check the the values. Missing data might cause surprises.
function [ day_number, daily_rain ] = DailyRain( RainData, year_number, month_number )
day_number = [ RainData(:).DayNumber ];
is_yy = ( year( day_number ) == year_number );
is_mm = ( month( day_number ) == month_number );
is_ym = ( is_yy & is_mm );
if any( is_ym )
daily_rain = [ RainData( is_ym ).DailyRain ];
day_number = [ RainData( is_ym ).DayNumber ];
else
daily_rain = [ ];
day_number = [ ];
end
end
32 Kommentare
Soni huu
am 6 Jul. 2012
⋮
-
Verknüpfen
Direkter Link zu diesem Kommentar
( day_number, daily_rain ) graph
>> figure, plot( day_number, daily_rain, '.' )
>> figure, plot( day_number, '.' )
%why y= 0 to 3000 and axes/x = (7.348 to 73484) x10^5
per isakson
am 6 Jul. 2012
⋮
-
Verknüpfen
Direkter Link zu diesem Kommentar
Regarding "y= 0 to 3000" either
- the data sum up to something close to 3000 or
- an error in the code
Reagrding (7.348 to 73484) x10^5
- some hours ago you used datetick, but not here
Soni huu
am 6 Jul. 2012
⋮
-
Verknüpfen
Direkter Link zu diesem Kommentar
how to fix it?
per isakson
am 6 Jul. 2012
⋮
-
Verknüpfen
Direkter Link zu diesem Kommentar
Try
hist( [ RainData.DailyRain ], 100 )
[ mx, ixm ] = max( [ RainData.DailyRain ] );
plot( datenum( RainData( ixm ).Datevec ), RainData( ixm ).Rain )
datetick
title( RainData(ixm).DataFile )
Soni huu
am 6 Jul. 2012
⋮
-
Verknüpfen
Direkter Link zu diesem Kommentar
title( RainData(ixm).DataFile )
Warning: Unable to interpret TeX string "\matlab7\work\org\2011\08-24-2011.dat".
per isakson
am 6 Jul. 2012
⋮
-
Verknüpfen
Direkter Link zu diesem Kommentar
Bearbeitet: per isakson
am 6 Jul. 2012
Try
is_huge = ( [ RainData.DailyRain ] >= 2500 );
RainData(is_huge).DataFile
total rain of eight different files exceeds 2500. Is there a problem with units? You must check the code!
Soni huu
am 6 Jul. 2012
⋮
-
Verknüpfen
Direkter Link zu diesem Kommentar
8 result like this
ans =
C:\matlab7\work\org\2011\04-14-2011.dat
per isakson
am 6 Jul. 2012
⋮
-
Verknüpfen
Direkter Link zu diesem Kommentar
Remember the function, EscapeBackSlash?
Soni huu
am 6 Jul. 2012
⋮
-
Verknüpfen
Direkter Link zu diesem Kommentar
yes, i still save
Soni huu
am 6 Jul. 2012
⋮
-
Verknüpfen
Direkter Link zu diesem Kommentar
Bearbeitet: Soni huu
am 6 Jul. 2012
oke this the title diagram
C:\matlab7\work\org\2011\09-24-2011.dat
can matlab change title to "graphic rainrate 09-24-2011" (just read name of file plus graphic rainrate)
per isakson
am 6 Jul. 2012
⋮
-
Verknüpfen
Direkter Link zu diesem Kommentar
Bearbeitet: per isakson
am 6 Jul. 2012
Try
>> doc datetick
.
I'm lost! You know what the numbers mean. I don't!
per isakson
am 6 Jul. 2012
⋮
-
Verknüpfen
Direkter Link zu diesem Kommentar
"yes, i still save"
save what?
Soni huu
am 6 Jul. 2012
⋮
-
Verknüpfen
Direkter Link zu diesem Kommentar
Bearbeitet: Soni huu
am 6 Jul. 2012
i mean still have EscapeBackSlash.m
function str = EscapeBackSlash( str )
str = strrep( str, '\', '\\' );
end
per isakson
am 6 Jul. 2012
⋮
-
Verknüpfen
Direkter Link zu diesem Kommentar
Bearbeitet: per isakson
am 6 Jul. 2012
My points were
- title( EscapeBackSlash( RainData(ixm).DataFile ) ) to avoid the warning and
- you shouldn't rely that much on me; you must try harder to understand what the functions do
Soni huu
am 7 Jul. 2012
⋮
-
Verknüpfen
Direkter Link zu diesem Kommentar
Bearbeitet: Soni huu
am 7 Jul. 2012
ur code is work
but in the end....
GUI matlab 7. 2004 r14 not support in w7 64 bit sp1.. now i have to buy matlab 2012b.. :(
per isakson
am 7 Jul. 2012
⋮
-
Verknüpfen
Direkter Link zu diesem Kommentar
Bearbeitet: per isakson
am 7 Jul. 2012
R2012a and I guess R2012b are improved in many respects compared to the 2004 version. The 64 bit version of Matlab can handle more memory, e.g larger arrays.
I'm happy you say that!
"why y= 0 to 3000 ": Did you figure out what unit is used for the rain in column three?
Soni huu
am 7 Jul. 2012
⋮
-
Verknüpfen
Direkter Link zu diesem Kommentar
Bearbeitet: Soni huu
am 7 Jul. 2012
"why y= 0 to 3000 ": Did you figure out what unit is used for the rain in column three?
problem solve: column three is (mm/h) to change we have to devide by 60(coz data is every 1 minutes) : i was change the code;
rain_data.Rainrate = cac{3};
rain_data.Rain = (rain_data.Rainrate)/60;
rain_data.DailyRain = sum( rain_data.Rain );
please correct
and i want add new variable; temperature
rain_data.suhu = cac{9};
rain_data.meansuhu = mean(rain_data.suhu );
rain_data.maxsuhu = max (rain_data.suhu );
rain_data.minsuhu = min(rain_data.suhu );
per isakson
am 7 Jul. 2012
⋮
-
Verknüpfen
Direkter Link zu diesem Kommentar
It's correct. However, an alternative is
rain_data.Rainrate = cac{3}; % [mm/h]
rain_data.DailyRain = 24*mean( rain_data.Rain ); % [mm]
Pros:
- this is easier to understand. The average rain rate [mm/h] times 24 hour per day, which gives [mm].
- this will handle missing data somewhat better. Missing data will be replace by the average of available data.
- this will work with a data file with other sampling rates, e.g. 2-minute data
- the confusing quantity, RainData.Rain [mm/minute], is not visible outside the function.
Soni huu
am 7 Jul. 2012
⋮
-
Verknüpfen
Direkter Link zu diesem Kommentar
this will work with a data file with other sampling rates, e.g. 2-minute data: how can be?? if posible, ok..
per isakson
am 7 Jul. 2012
⋮
-
Verknüpfen
Direkter Link zu diesem Kommentar
Assume the rain_rate varies as a sinus plus some noise. Sample it 1,2,4,8 minutes and estimate daily total. Try
tt = transpose( 1 : 1 : 60 * 24 );
rain_rate_1_min = max( 0, 7*(1+sin(8*pi*tt/(60*24))) + 4*randn(60*24,1) );
rain_rate_2_min = rain_rate_1_min( 1 : 2 : end );
rain_rate_4_min = rain_rate_1_min( 1 : 4 : end );
rain_rate_8_min = rain_rate_1_min( 1 : 8 : end );
plot( rain_rate_1_min )
total = [ 24 * mean( rain_rate_1_min )
24 * mean( rain_rate_2_min )
24 * mean( rain_rate_4_min )
24 * mean( rain_rate_8_min ) ]
The four values are close. Now, you make an analytic prof (paper and pencil).
Soni huu
am 9 Jul. 2012
⋮
-
Verknüpfen
Direkter Link zu diesem Kommentar
Bearbeitet: Soni huu
am 9 Jul. 2012
i can find 2012a in here, not yet.. if i download, my conection so slowly
RainData = ReadManySoniData( 'C:\matlab7\work\org\2011', '*.dat' ) its work...
but RainData = ReadManySoniData( 'C:\matlab7\work\org\ 2010 ', '*.dat' )
Trouble reading literal string from file (row 543, field 9) ==> \n
Error in ==> strread at 51
[varargout{1:nlhs}]=dataread('string',varargin{:},'bufsize',2*num );
Error in ==> ReadOneSoniData at 22
[cac{:}] = strread( str, '%8c%2c%4f%7f%4c%4u%4u%4u+%2u' ...
Error in ==> ReadManySoniData at 5
RainData = cat( 2, RainData, ReadOneSoniData( folder_name, sa.name ) );
per isakson
am 9 Jul. 2012
⋮
-
Verknüpfen
Direkter Link zu diesem Kommentar
Bearbeitet: per isakson
am 9 Jul. 2012
I guess a dat-file in 'C:\matlab7\work\org\ 2010 ' contains a line that causes this error.
There is a space after "2010" - mistake?
Hint: "(row 543, field 9)"
Soni huu
am 9 Jul. 2012
⋮
-
Verknüpfen
Direkter Link zu diesem Kommentar
no space. space just to make bold. how to fin error data?
per isakson
am 9 Jul. 2012
⋮
-
Verknüpfen
Direkter Link zu diesem Kommentar
dbstop if error
Soni huu
am 9 Jul. 2012
⋮
-
Verknüpfen
Direkter Link zu diesem Kommentar
this the result.. i cant find error data
RainData = ReadManySoniData( 'C:\matlab7\work\org\2010', '*.dat' );
??? Trouble reading literal string from file (row 543, field 9) ==> \n
Error in ==> strread at 51
[varargout{1:nlhs}]=dataread('string',varargin{:},'bufsize',2*num );
Soni huu
am 9 Jul. 2012
⋮
-
Verknüpfen
Direkter Link zu diesem Kommentar
can we show all data at row 543?
Soni huu
am 9 Jul. 2012
⋮
-
Verknüpfen
Direkter Link zu diesem Kommentar
Bearbeitet: Soni huu
am 9 Jul. 2012
i found the error data.. sometime table just have 7 field.
08:58:00 .000 005.810 01** 4850 0058 0058 +24
08:59:00 .000 005.810 01** 4852 0058 0058 +24
09:00:00 .000 005.810 01** 4854 0058 0058 +24
09:01:00 .000 005.810 01** 4852 0058 0058 +24
09:02:00 .000 005.810 01** 4856 0
how to eliminate error data?
per isakson
am 10 Jul. 2012
⋮
-
Verknüpfen
Direkter Link zu diesem Kommentar
Bearbeitet: per isakson
am 10 Jul. 2012
First step: In ReadManySoniData replace
RainData = cat( 2, RainData, ReadOneSoniData( folder_name, sa.name )
by
try
RainData = cat( 2, RainData, ReadOneSoniData(folder_name,sa.name)
catch
fprintf( 'Folder: %s\nFile: %s\n', foldername, sa.name )
disp( lasterr )
end
.
Second step: Run ReadManySoniData for all data files you have. That will give you a list of files, which cause troubles, in the command window.
Third step: Inspect the files (causing trouble) with an editor. Make a list with the lines, which you think are the cause of the trouble.
Fourth step: What do these lines have in common? How can these lines be identified? By what rule?
Soni huu
am 12 Jul. 2012
⋮
-
Verknüpfen
Direkter Link zu diesem Kommentar
RainData = ReadManySoniData( 'C:\matlab7\work\org\2011', '*.dat' );
??? Error: File: C:\matlab7\work\org\ReadManySoniData.m Line: 5 Column: 76
Incomplete or misformed expression or statement.
per isakson
am 12 Jul. 2012
⋮
-
Verknüpfen
Direkter Link zu diesem Kommentar
Bearbeitet: per isakson
am 13 Jul. 2012
You know - not me - whats on line: 5 column: 76. Fix the line! I guess it is a typing error.
Make sure the Code Analyzer box is green before you run the code.
Soni huu
am 24 Aug. 2012
⋮
-
Verknüpfen
Direkter Link zu diesem Kommentar
thanks per isakson... u save me... :)
per isakson
am 24 Aug. 2012
⋮
-
Verknüpfen
Direkter Link zu diesem Kommentar
Soni, good to hear that you succeeded to read the data
Siehe auch
Kategorien
Mehr zu Tall Arrays finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Es ist ein Fehler aufgetreten
Da Änderungen an der Seite vorgenommen wurden, kann diese Aktion nicht abgeschlossen werden. Laden Sie die Seite neu, um sie im aktualisierten Zustand anzuzeigen.
Website auswählen
Wählen Sie eine Website aus, um übersetzte Inhalte (sofern verfügbar) sowie lokale Veranstaltungen und Angebote anzuzeigen. Auf der Grundlage Ihres Standorts empfehlen wir Ihnen die folgende Auswahl: .
Sie können auch eine Website aus der folgenden Liste auswählen:
So erhalten Sie die bestmögliche Leistung auf der Website
Wählen Sie für die bestmögliche Website-Leistung die Website für China (auf Chinesisch oder Englisch). Andere landesspezifische Websites von MathWorks sind für Besuche von Ihrem Standort aus nicht optimiert.
Amerika
- América Latina (Español)
- Canada (English)
- United States (English)
Europa
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom(English)
Asien-Pazifik
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)
