Save values of for loop inside matrix

1 view (last 30 days)
Lulu Dulac
Lulu Dulac on 6 Jul 2017
Edited: Jan on 6 Jul 2017
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 Comment
KSSV
KSSV on 6 Jul 2017
What are sizes of A1, A2 and A5? You need to look into horzcat and vertcat..

Sign in to comment.

Answers (1)

Jan
Jan on 6 Jul 2017
Edited: Jan on 6 Jul 2017
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.

Categories

Find more on Creating and Concatenating Matrices in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!