Concatenating columns from a for loop.

2 次查看(过去 30 天)
Shaun
Shaun 2015-2-17
编辑: Shaun 2015-2-20
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{:});

回答(1 个)

Jan
Jan 2015-2-17
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 个评论
Shaun
Shaun 2015-2-17
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.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Matrices and Arrays 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by