array assignment with and without semicolon
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
If this is already be in the FAQ please direct me to the relevant FAQ section, if not here is my question I am assigning parts of an larger array to a smaller array I am using it in a loop, my statement are (1) and (2); (1) runs without any error base on my limited understanding of the use of the semicolon (2) should run as well but Matlab returns an error "Subscripted assignment dimension mismatch".
a and b changes inside the loop, can someone help understand what the issue is with the use of (2)? Thanks, Philip
xbit_1 = xbit(a:b,1); (1)
xbit_1(:,1) = xbit(a:b,1); (2)
0 commentaires
Réponse acceptée
Thorsten
le 1 Déc 2015
The problem is when a and b change such that the number of elements in a:b change. If you have, say, n elements in a:b for the first run of the loop, xbit_1 is n x 1. If now the number of elements in a:b change in another run of the loop, say to n + 3, you try to assign n+3 values to a n x 1 matrix. That does not work. Instead, use
xbit_1(1:numel(a:b),1) = xbit(a:b,1);
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!