The variable "X" might be used before it is defined
Afficher commentaires plus anciens
Is something wrong because of that red line? The program can't find that file?

How can I solve this problem? Thanks
6 commentaires
Walter Roberson
le 26 Oct 2017
You do not show us any code that uses a variable "X".
João Carvalho
le 26 Oct 2017
per isakson
le 26 Oct 2017
Modifié(e) : per isakson
le 26 Oct 2017
What's in g1_land.txt? I guess load g1_land.txt fails. Is it a lowercase L or a one?
Walter Roberson
le 26 Oct 2017
Duplicated by later https://www.mathworks.com/matlabcentral/answers/363470-the-variable-g1_land-might-be-used-before-it-is-defined-error and requires merging
João Carvalho
le 26 Oct 2017
per isakson
le 26 Oct 2017
I would try to interactively run
data = load( c:\mydata\folder\g1_land.txt', '-ascii' );
with your full file specification in the command window.
Réponses (1)
OCDER
le 26 Oct 2017
Using load without an output is essentially "poofing" variables into your function and forcing the rest of the code to "guess" what variable got poofed in. That's what the warning message is telling you: The variable "g1_land" might be used before it's defined.
To fix this:
g1_land = load('g1_land.txt'); %Now, you explicitly told the computer what g1_land is.
"Hey Matlab, I'm importing data into a variable called g1_land,
so no surprises!"
ano1 = g1_land(:, 1);
Note that if g1_land.txt is formatted incorrectly, you'll get other errors. There are other ways to import data, like csvread, dlmread, fscanf, textscan, etc.
Catégories
En savoir plus sur Workspace Variables and MAT Files dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!