Storing values from a for-loop in a matrix. Error: Subscripted assignment dimension mismatch.
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
John Mathew
il 27 Apr 2015
Commentato: John Mathew
il 27 Apr 2015
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
0 Commenti
Risposta accettata
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);
Più risposte (0)
Vedere anche
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!