Concatenating columns from a for loop.

2 views (last 30 days)
Shaun
Shaun on 17 Feb 2015
Edited: Shaun on 20 Feb 2015
Hi, So I have some code that creates a column of data in each run of a for loop. I want to concatenate those columns to build an array once the for loop has finished. So far I have....
vals = cell(size(images, 3), 2);
T2ind = cell(size(images, 1), 1);
T2 = cell(size(images, 1), size(images, 2));
for y = 1:size(images,1)
for x = 1:size(images,2)
if ((sum(images(y,x,:))/size(images, 3)) > 100)
for z = 1:size(images, 3)
echo = dat(z, 6);
imgVal = images(y,x,z);
vals(z,:) = {echo, imgVal};
end
f = fit(cell2mat(cellfun(@cell2mat, vals(:,1), 'UniformOutput', false)), cell2mat(vals(:,2)), 'exp1');
coeff = coeffvalues(f);
a= coeff(1);
b = coeff(2);
S1 = f(10);
S2 = S1/exp(1);
T2ind{x} = {((log(S2/a))/b)};
end
end
T2(y,:) = cat(1, T2ind{:});
end
The idea being that T2 will be my array of 256 by 256 data points constructed from the 256 T2ind columns. I get a subscripted assignment dimension mismatch error for T2. Any help would be great! Thanks!
Error:
Subscripted assignment dimension mismatch.
Error in T2_mapping (line 60)
T2(y, :) = cat(1, T2ind{:});

Answers (1)

Jan
Jan on 17 Feb 2015
Please post a complete copy of the error message in every case. Thanks.
T2(y,:) = cat(1, T2ind{:});
The right hand side is a row vector, the left hand side a column vector. Are you sure you want to apply CAT here?
  1 Comment
Shaun
Shaun on 17 Feb 2015
I've added the error code. So I want a set of columns (T2ind) to be concatenated into an array (T2). So,
T2(y,:) = cat(2, T2ind{:});
would be better? I tried that and got the same error. not sure if that's what you mean.

Sign in to comment.

Categories

Find more on Matrices and Arrays 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!