필터 지우기
필터 지우기

How to combine workspaces using the workspace name

조회 수: 35 (최근 30일)
Lauren
Lauren 2013년 5월 9일
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
per isakson
per isakson 2013년 5월 9일
편집: per isakson 2013년 5월 9일
In Matlab "workspace" is something different. Your, A1,A2,... are variables.
You overwrite the variable, a, 199 times.

댓글을 달려면 로그인하십시오.

채택된 답변

Walter Roberson
Walter Roberson 2013년 5월 9일

추가 답변 (1개)

Matt J
Matt J 2013년 5월 9일
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{:});

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by