現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
how to make monthly graph from daily file data
2 ビュー (過去 30 日間)
古いコメントを表示
Soni huu
2012 年 7 月 6 日
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 件のコメント
per isakson
2012 年 7 月 6 日
"from this code (daily/1 file) can u make monthly graph (30file data)??"
Put more effort in describing what you need!
採用された回答
per isakson
2012 年 7 月 6 日
編集済み: per isakson
2012 年 7 月 6 日
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 件のコメント
Soni huu
2012 年 7 月 6 日
its work.. how about daily?? i just to make 12 folder, one folder to one month?
per isakson
2012 年 7 月 6 日
編集済み: per isakson
2012 年 7 月 6 日
Not needed! I'm worried about missing data and how that should be reported. In next version?
Soni huu
2012 年 7 月 11 日
> mr = MonthlyRain( RainData ); work
>> plot( mr(1).Rain, 'd' ); work
>> bar( mr.Rain ); not work for 2010 data, just 1 vertikal line..
per isakson
2012 年 7 月 11 日
Have you solved the problem with reading the 2010 data?
what does
[ mr.Rain ]
return?
per isakson
2012 年 7 月 12 日
編集済み: per isakson
2012 年 7 月 12 日
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
2012 年 7 月 12 日
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
2012 年 7 月 12 日
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
2012 年 7 月 12 日
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
2012 年 7 月 12 日
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
per isakson
2012 年 7 月 12 日
編集済み: per isakson
2012 年 7 月 12 日
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
2012 年 7 月 12 日
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
2012 年 7 月 12 日
"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
2012 年 7 月 12 日
編集済み: Soni huu
2012 年 7 月 12 日
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
2012 年 7 月 12 日
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
2012 年 7 月 12 日
編集済み: per isakson
2012 年 7 月 12 日
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
2012 年 7 月 12 日
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
2012 年 7 月 12 日
編集済み: per isakson
2012 年 7 月 12 日
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
2012 年 7 月 12 日
編集済み: Soni huu
2012 年 7 月 12 日
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
2012 年 7 月 12 日
編集済み: per isakson
2012 年 7 月 12 日
Replace
foldername
by
folder_name
.
The Code Analyzer box was it green before you run the code?
Soni huu
2012 年 7 月 12 日
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 ));
per isakson
2012 年 7 月 12 日
編集済み: per isakson
2012 年 7 月 12 日
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
2012 年 7 月 12 日
編集済み: Soni huu
2012 年 7 月 12 日
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
2012 年 7 月 12 日
"06:39:00" appears three times. Does that mean anything?
What rule would you propose for removing rows?
per isakson
2012 年 7 月 12 日
編集済み: per isakson
2012 年 7 月 12 日
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
2012 年 7 月 12 日
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
per isakson
2012 年 7 月 12 日
編集済み: per isakson
2012 年 7 月 12 日
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
2012 年 7 月 12 日
編集済み: Soni huu
2012 年 7 月 12 日
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
2012 年 7 月 12 日
編集済み: per isakson
2012 年 7 月 12 日
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
2012 年 7 月 13 日
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
2012 年 7 月 13 日
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
2012 年 7 月 13 日
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' )
per isakson
2012 年 7 月 13 日
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
2012 年 7 月 13 日
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
2012 年 7 月 13 日
>> 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
2012 年 7 月 13 日
編集済み: per isakson
2012 年 7 月 13 日
- 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
2012 年 7 月 13 日
magic_length = 47; % ignore lines with length <= magic_length
"01-01-2010.dat" (14 string) <= 47
but i think i was wrong
Soni huu
2012 年 7 月 13 日
le=lasterror
le =
le =
message: [1x46 char]
identifier: 'MATLAB:minrhs'
??? le = |
Error: Incomplete or misformed expression or statement.
per isakson
2012 年 7 月 13 日
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
2012 年 7 月 13 日
In ReadManySoniData replace
disp( le.stack(1) )
disp( le.message )
by
disp( le.message )
disp( le.identifier )
disp( le.stack(1) )
Soni huu
2012 年 7 月 13 日
>> 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) )
per isakson
2012 年 7 月 13 日
編集済み: per isakson
2012 年 7 月 13 日
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' );
per isakson
2012 年 7 月 13 日
Run ReadOneSoniData
>> ReadOneSoniData( 'C:\matlab7\work\org\2010', '01-01-2010.dat' )
Soni huu
2012 年 7 月 13 日
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
2012 年 7 月 13 日
>> 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
2012 年 7 月 13 日
編集済み: per isakson
2012 年 7 月 13 日
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
2012 年 7 月 13 日
編集済み: Soni huu
2012 年 7 月 13 日
>> 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
2012 年 7 月 13 日
編集済み: Soni huu
2012 年 7 月 13 日
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
2012 年 7 月 13 日
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.
per isakson
2012 年 7 月 13 日
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.
その他の回答 (1 件)
per isakson
2012 年 7 月 6 日
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 件のコメント
Soni huu
2012 年 7 月 6 日
( 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
2012 年 7 月 6 日
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
per isakson
2012 年 7 月 6 日
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
2012 年 7 月 6 日
title( RainData(ixm).DataFile )
Warning: Unable to interpret TeX string "\matlab7\work\org\2011\08-24-2011.dat".
per isakson
2012 年 7 月 6 日
編集済み: per isakson
2012 年 7 月 6 日
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!
per isakson
2012 年 7 月 6 日
編集済み: per isakson
2012 年 7 月 6 日
Try
>> doc datetick
.
I'm lost! You know what the numbers mean. I don't!
per isakson
2012 年 7 月 6 日
編集済み: per isakson
2012 年 7 月 6 日
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
per isakson
2012 年 7 月 7 日
編集済み: per isakson
2012 年 7 月 7 日
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
2012 年 7 月 7 日
編集済み: Soni huu
2012 年 7 月 7 日
"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
2012 年 7 月 7 日
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
2012 年 7 月 7 日
this will work with a data file with other sampling rates, e.g. 2-minute data: how can be?? if posible, ok..
per isakson
2012 年 7 月 7 日
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
2012 年 7 月 9 日
編集済み: Soni huu
2012 年 7 月 9 日
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
2012 年 7 月 9 日
編集済み: per isakson
2012 年 7 月 9 日
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
2012 年 7 月 9 日
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
2012 年 7 月 9 日
編集済み: Soni huu
2012 年 7 月 9 日
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
2012 年 7 月 10 日
編集済み: per isakson
2012 年 7 月 10 日
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
2012 年 7 月 12 日
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
2012 年 7 月 12 日
編集済み: per isakson
2012 年 7 月 13 日
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.
参考
カテゴリ
Help Center および File Exchange で Target Language Compiler についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の MathWorks のサイトは、お客様の地域からのアクセスが最適化されていません。
南北アメリカ
- América Latina (Español)
- Canada (English)
- United States (English)
ヨーロッパ
- 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)
アジア太平洋地域
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)