concatenate 3 dimensional matrix in a loop

1 Ansicht (letzte 30 Tage)
Yuvashree Mani Urmila
Yuvashree Mani Urmila am 12 Jun. 2014
Beantwortet: Titus Edelhofer am 12 Jun. 2014
I have 128 matrices( n*32) stored in a dataStructure. I want to concatenate these matrices in 3 dimensional so its possible for me to calculate the mean in the third dimension.
for fileNr =1:nrOfFiles outputFileName = outputFileNames(fileNr); outputFileName = outputFileName{1}; outputFileName = strcat(outputFolder, filesep, outputFileName);
FileName=(outputFileName);
data=load(FileName)
data=data2.dataStruct.data
end
i wrote a code like this to get the data from the data structure. how do i concatenate the matrices(in data) after every loop using cat function.

Akzeptierte Antwort

Titus Edelhofer
Titus Edelhofer am 12 Jun. 2014
Hi,
you can concatenate like follows in the loop
allData(:,:,fileNr) = data;
but if you "only" want to compute the mean, there is no need to blow up the memory like this, simply do: in the loop
if fileNr == 1
meanData = data;
else
meanData = meanData + data;
end
and after the loop
meanData = meanData / nrOfFiles;
Titus

Weitere Antworten (0)

Kategorien

Mehr zu Random Number Generation finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by