I am new to MatLab so forgive my lack of knowledge here:
I want to iterate over multiple variables stored in a .mat file.
I have the following simple test code:
object = load('test.mat');
for name = fieldnames(object)
disp(length(name))
x = object.(name{1})(:,1);
y = object.(name{1})(:,2);
disp('LOOP')
end
disp('DONE')
Clearly, this code should load test.mat (which has two variables in it: test, and testCopy, which are 90x2 doubles). The for loop should, for each variable, assign the first column to X and the second column to y, and then display LOOP.
Since test.mat has two variables, I should display LOOP twice and DONE once. However, The output is as follows - it's not iterating!
>>program
2
LOOP
DONE
I'm totally stumped - the program knows that the length of "name" is 2, and so the loop should be executed twice. What am I missing? Thanks in advance for your help.