1

I only want to load some of the variables from a lot of.mat files (a1.mat, a2.mat.....) into the .m file, and use them as function. Here is my code

files=dir('a*.mat'); 
numfiles=length(files);

for k=1:numfiles
filename=files(k).name;
data=load(filename,'Name','Age','Country');
end

data_jan_name=[data.Name]

However, it always returns an error message:

??? Undefined variable "data" or function "data.Name".
infused
  • 24,000
  • 13
  • 68
  • 78
manxing
  • 3,165
  • 12
  • 45
  • 56

1 Answers1

0

This all looks good. I would check that it is actually running through the for loop. Let it print out file name. Otherwise, perhaps those Variables Name, Age and Country don't exist in the files, so maybe let it print data as well.

If you show us what a regular a.mat file looks like I can expand on this answer.

Fantastic Mr Fox
  • 32,495
  • 27
  • 95
  • 175