Storing values from a for-loop in a matrix. Error: Subscripted assignment dimension mismatch.

3 次查看(过去 30 天)
Hello everybody,
I have been reading the forums the whole day and trying different combinations to solve my problem but I could not get an answer yet.
T1' is a 1x50-row-vector, T_iso1 is a 50x50-square-matrix, and bsfc1 is also a 50x50-square-matrix.
I want to store in a matrix the column-vectors vq from the interpolation for every i. I can run the code and get a column vector vq for every i, but then I only store the last one. However, when I try to store them all in a matrix A I get always the error 'Subscripted assignment dimension mismatch.'
The code is the following:
lim=50;
for i=1:lim
x = T1';
xq = T_iso1(:,i);
v = bsfc1(:,i)';
vq= interp1(x,v,xq,'spline')
A(:,i) = vq;
end
Could anybody help me out? I would appreciate any comment.
Thank you very much in advance,
John

采纳的回答

James Tursa
James Tursa 2015-4-27
Your code runs fine for me with random inputs as follows:
Name Size
T1 50x1
T_iso1 50x50
bsfc1 50x50
Maybe you have an "A" variable floating around with a different size? Try pre-allocating "A" first. E.g.,
A = zeros(50,lim);
  1 个评论
John Mathew
John Mathew 2015-4-27
Oh my god! Thank you James. I have been trying so many different things today that I did not pay attention to the basics... Yes, it was exactly what you said. Thank you!

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Interpolation 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by