A string related MAT file question

My variables are stored as Var1 and Var2 in my MAT file. My goal is to write a loop so that I can read them out one at a time. Why doesn’t the below work?

using MAT;
F1  = matopen("Path1/File1.mat");
for i ∈ ["Var1", "Var2", ...];
    A  = read(F1, $(i));
end
close(F1);

This surely work though.
A = read(F1, "Var1");

Isn’t $(1) = “Var1”?

Thanks!

No dollar signs are needed here. This is just an ordinary use of a variable i:

for i ∈ ["Var1", "Var2", ...]
    A  = read(F1, i)
    # do something with A here…
end

(Also you don’t need a semicolon after every line.) (And you probably don’t want to close the file until the end of the loop?

1 Like

It works!

Many thanks.