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

1 visualizzazione (ultimi 30 giorni)
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

Risposta accettata

James Tursa
James Tursa il 27 Apr 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 Commento
John Mathew
John Mathew il 27 Apr 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!

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Loops and Conditional Statements in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by