I have code that pulls files successfully except once the first loop is completed fnm is overwritten and the previous files contents disappear. I need to add code that allows each loop to store the file contents(a Matrix). Once the files are saved and the for loop is complete dependent of the size(CatRow)I will concatenate the matrixes together.
%
for ii= 1: CatRow
[num,txt,data] = xlsread(stateTable{ii,1})
fnm = sprintf('file_%d.mat',ii);
save(fnm,'data');
horzcat(fnm's into one matrix)
end

 채택된 답변

Walter Roberson
Walter Roberson 2018년 1월 10일
편집: Walter Roberson 2018년 1월 10일

0 개 추천

all_data = cell(CatRow,1);
for ii= 1: CatRow
[num,txt,data] = xlsread(stateTable{ii,1})
fnm = sprintf('file_%d.mat',ii);
save(fnm,'data');
all_data{ii} = data;
end
big_data = horzcat(all_data{:});
I have to ask whether you really want to horzcat() them together. If they are the same size, more common would be to
big_data = cat(3, all_data{:});
which would concatenate them on the third dimension.

댓글 수: 2

Tessa Aus
Tessa Aus 2018년 1월 10일
편집: Tessa Aus 2018년 1월 10일
It looks like it worked but it is now a 2x1 cell with each matrix inside each cell? How do I pull the data out of the cells?
matrix has I am not concatenating the more common way because I must do the same for all columns in the future as the user can specify and create any number of column and row matrix sizes to break down one large one.
Walter Roberson
Walter Roberson 2018년 1월 10일
I had some typing mistakes in what I posted; I have corrected them.
To get a 2 x 1 cell you must have used vertcat() or cat(1) instead of horzcat()

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

질문:

2018년 1월 10일

댓글:

2018년 1월 10일

Community Treasure Hunt

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

Start Hunting!

Translated by