# Calling matrices from workspace to For loop in MATLAB

#### omri3012

Hallo,

I have matrices on my workpace and i need to take the first element from each one
and produce new vector. In other words, i have the matrices D1,D2,D3....D36 on my workspace and by using a For loop i want to generate a new vector:
d=[D1(1,1) D2(1,1)...D3(1,1)].
does anyone know how to that in For loop?

Thanks,
Omri

Related MATLAB, Maple, Mathematica, LaTeX, Etc News on Phys.org

#### matonski

Code:
for i = 1:36
s = sprintf('d(i) = D%g(1,1);',i);
eval(s);
end

#### omri3012

Thanks,
It's working now, i really appreciate it!

Omri

Last edited:

"Calling matrices from workspace to For loop in MATLAB"

### Physics Forums Values

We Value Quality
• Topics based on mainstream science
• Proper English grammar and spelling
We Value Civility
• Positive and compassionate attitudes
• Patience while debating
We Value Productivity
• Disciplined to remain on-topic
• Recognition of own weaknesses
• Solo and co-op problem solving