fprint error
12 次查看(过去 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 个)
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.
Image Analyst
2012-6-21
You need to specify particular fields in your struct, like ug.field1, vg.field42, v.myField, or whatever...
0 个评论
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!