joining two arrays to make a longer one

조회 수: 4 (최근 30일)
Locks
Locks 2013년 4월 7일
If I have two arrays, lets say the first is called a and the second is called b, I am aware of the fact that I can combine them with the command A=[a;b] to get a longer array
the problem I have got now is the following: I have two matlab files (let's say the first one is year 2002 and the second one from year 2003) which are saved in my computer and wich I would like to load, what is no big deal. Ich matlab file consist of 8 vectors which are called F,K,PC,Price,T,VIX,date,r
loading this is no problem, but as soon as I an loading both files, because the arrays in the files have the same name, the second file is overwriting the first one is there a way to write a code in a script which loads both files and combines them the way I mentionned above without overwriting the first file?

채택된 답변

Image Analyst
Image Analyst 2013년 4월 7일
You aren't using load correctly. You need to load each into its own structure
storedStructure1 = load(filename1);
storedStructure2 = load(filename2);
% Get theResults (or whatever) from each
theResults1 = storedStructure1.theResults;
theResults2 = storedStructure2.theResults;
% Concatenate
theResults = [theResults1; theResults2];

추가 답변 (1개)

Cedric
Cedric 2013년 4월 7일
편집: Cedric 2013년 4월 7일
If all vectors are column vectors, do the following:
data = [] ;
for f = 1 : nFiles
% Load file f:
% ... whatever you are doing to load the file.
% CAT to data array:
data = vertcat(data, [F,K,PC,Price,T,VIX,date,r]) ;
end
if these are row vectors, just transpose them. If it is a mix and you don't want to investigate, just read them linearly ( => column ):
data = vertcat(data, [F(:),K(:),PC(:),Price(:),T(:),VIX(:),date(:),r(:)]) ;
  댓글 수: 10
Locks
Locks 2013년 4월 8일
great, that seems to work, thanks!
Locks
Locks 2013년 4월 8일
편집: Locks 2013년 4월 8일
What I still do not reallly understand is how that is working, or in other words which element is allowing me to load the data without overwriting them, could you explain that to me? Is seems as 2002 is stored in ld, but I do not get what ld is and how it's done then

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

카테고리

Help CenterFile Exchange에서 App Building에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by