The variable "X" might be used before it is defined

Is something wrong because of that red line? The program can't find that file?
How can I solve this problem? Thanks

댓글 수: 6

You do not show us any code that uses a variable "X".
the variable is "g1_land"
per isakson
per isakson 2017년 10월 26일
편집: per isakson 2017년 10월 26일
What's in g1_land.txt? I guess load g1_land.txt fails. Is it a lowercase L or a one?
In "g1_land.txt" there are three columns with numbers. It is a lowercase L.
I would try to interactively run
data = load( c:\mydata\folder\g1_land.txt', '-ascii' );
with your full file specification in the command window.

댓글을 달려면 로그인하십시오.

답변 (1개)

OCDER
OCDER 2017년 10월 26일
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.

카테고리

도움말 센터File Exchange에서 Workspace Variables and MAT Files에 대해 자세히 알아보기

질문:

2017년 10월 26일

댓글:

2017년 10월 26일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by