fprint error
17 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponses (4)
Image Analyst
le 21 Juin 2012
You need to specify particular fields in your struct, like ug.field1, vg.field42, v.myField, or whatever...
0 commentaires
Geoff
le 21 Juin 2012
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 commentaires
Geoff
le 21 Juin 2012
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
le 21 Juin 2012
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 commentaires
Walter Roberson
le 21 Juin 2012
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
le 21 Juin 2012
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.
Voir également
Catégories
En savoir plus sur File Operations dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!