fprint error
조회 수: 17 (최근 30일)
이전 댓글 표시
Itry process multiple data..sometimes, my programming working..but,when i want to repeat processing, appear error like below..can someone help me to solve this error
??? Error using ==> fprintf Function is not defined for 'struct' inputs.
Error in ==> Dailystep2 at 154 fprintf(fid,'\n%15.6f%15.6f%15.6f%15.6f%15.6f%15.6f%15.6f%15.6f\n',LAT,LON,ug,vg,dir,v,EKE,he1);
댓글 수: 0
답변 (4개)
Image Analyst
2012년 6월 21일
You need to specify particular fields in your struct, like ug.field1, vg.field42, v.myField, or whatever...
댓글 수: 0
Geoff
2012년 6월 21일
Like the error message says, some of your inputs are structs, and that's not allowed. Run the following code to check the types that you are passing to fprintf:
cellfun( @class, {LAT,LON,ug,vg,dir,v,EKE,he1}, 'uni', 0 )
댓글 수: 3
Geoff
2012년 6월 21일
Like walter said, don't use 'dir'. The problem here I think is that you do not guarantee that your variable will have a value. When you used 'dir', it wasn't so obvious because it just called the function instead of using the overridden variable name. You need something to fall back on. It seems like you use NaN for this purpose, but if ug and vg are both zero, and neither hd1 nor hd2 are NaN, you currently do not give 'd' any value.
Walter Roberson
2012년 6월 21일
Do not use "dir" as a variable name, as it conflicts with the function name "dir".
There are circumstances under which your if/else structure might not set the variable named "dir", so when your code tries to reference the unset variable "dir" it instead gets the function named "dir", runs that function which returns a structure...
"dir" as a variable can end up not being set if vg or ug come out as exactly 0, because you use < 0 and > 0 and do not consider exactly equal to 0.
댓글 수: 4
Walter Roberson
2012년 6월 21일
Using "elseif" would help prevent all those hanging "end" statements that give the impression to the reader that they should be looking back for a matching "for" loop.
Geoff
2012년 6월 21일
joo, check the comment in my answer. i suspect you never set a value for 'dir' (or 'd') because your block of if-statements does not handle one specific case, and you don't set the value anywhere else.
참고 항목
카테고리
Help Center 및 File Exchange에서 File Operations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!