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

3 visualizaciones (últimos 30 días)
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

Respuesta aceptada

James Tursa
James Tursa el 27 de Abr. de 2015
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 comentario
John Mathew
John Mathew el 27 de Abr. de 2015
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!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Interpolation en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by