Concatenating columns from a for loop.
3 次查看(过去 30 天)
显示 更早的评论
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{:});
0 个评论
回答(1 个)
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?
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrices and Arrays 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!