Save values of for loop inside matrix

1 次查看(过去 30 天)
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 中查找有关 Numeric Types 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by