- Calling clear to clear all variables is rarely necessary in a function.
- If you call load with an output argument, the output argument will be a struct array and the variables that were in the MAT-file will be read into fields in that output argument. This allows you to avoid conflicts with variables that already existed in the workspace. I recommend you use this approach; that way the name of the variable you have to access to use your data is predictable. You can use dynamic field names in conjunction with fieldnames if you don't know the names of the variables in your MAT-file but need to iterate over them.
.mat files not loading correctly
61 views (last 30 days)
I am very new to MATLAB, and the first program i wrote which loaded a file loaded a file named data_vector. Now, whenever I load any file it gets automatically stored in a variable of name data_vector. This means that the following code will not compile on my copy of MATLAB R2016b.
plot(test_data(1,:)) %test_data is a 1000x500 2D array
Edit: the specific error message is
Reference to a cleared variable test_data.
Error in phase_detector (line 4)
Steven Lord on 14 Apr 2017