Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

New to MATLAB?

How to combine workspaces using the workspace name

Asked by Lauren

Lauren (view profile)

on 9 May 2013

I have individual workspaces with names A1,A2,A3...A200. The workspaces all have two columns but varying number of rows. I have been trying:

for k=1:1:200
data=eval(sprintf('A%d',k);
a=[data];
end

However, this just gives me a workspace with the values from workspace A200. What is the most efficient way to combine all the workspaces into one with 2 columns?

1 Comment

per isakson

per isakson (view profile)

on 9 May 2013

In Matlab "workspace" is something different. Your, A1,A2,... are variables.

You overwrite the variable, a, 199 times.

Lauren

Lauren (view profile)

Products

No products are associated with this question.

2 Answers

Answer by Matt J

Matt J (view profile)

on 9 May 2013

Similar to what Walter said, it was a mistake to create A1...A200. It would have been much more efficient to have these matrices as elements of a cell array A{1}...A{200} instead. Then you would simply do

a=vertcat(A{:});

To undo the damage, you can do

 data=cell(1,200);
 for k=1:1:200
  data{k}=eval(sprintf('A%d',k);
 end
 a=vertcat(data{:});

1 Comment

Lauren

Lauren (view profile)

on 9 May 2013

Thanks!

Matt J

Matt J (view profile)

Contact us