Save values of for loop inside matrix

조회 수: 1 (최근 30일)
Lulu Dulac
Lulu Dulac 2017년 7월 6일
편집: Jan 2017년 7월 6일
Hi,
Please could anyone help me to save A1, A2 and A5 (which are 2D matrices) in a single matrix, and B1, B2 and B5 in another? I have tried with tableA(i,:) = [A1 A2 A5] but it tells me that Dimensions of matrices being concatenated are not consistent. Many thanks
p0 = 1;
p1 = floor(sizedata/5);
p5 = sizedata;
for i = 1:101
data = squeeze(fulldata(:,i,:));
A1 = data(p0:p4,:);
B1 = data(p4+1:end,:);
A5 = data(p1+1:end,:);
B5 = data(p0:p1,:);
A2 = [data(p0:p3,:); data(p4+1:p5,:)];
B2 = data(p3+1:p4,:);
end
  댓글 수: 1
KSSV
KSSV 2017년 7월 6일
What are sizes of A1, A2 and A5? You need to look into horzcat and vertcat..

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

답변 (1개)

Jan
Jan 2017년 7월 6일
편집: Jan 2017년 7월 6일
The shown code cannot work:
A1 = data(p0:p4,:);
A2 = [data(p0:p3,:); data(p4+1:p5,:)];
A5 = data(p1+1:end,:);
tableA(i,:) = [A1 A2 A5]
  1. A1 has p4-p0+1 rows, A2 has p3-p0+1 + p5-p4 rows, A5 has size(A, 1)-p1 rows. It is unlikely that these are the same numbers, please check this. If the number of rows are different, a horizontal concatenation is impossible: [A1 A2 A5].
  2. Even if this work, assigning it to the single row tableA(i,:) would fail, because you cannot assign a matrix to a vector.
Currently the readers cannot guess the intention of the code. Therefore you have to use the debugger at first: Go through the program line by line by setting breakpoints. Now find out what you want to achieve and how the arrays should be joined.

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by