I'm getting an error in the line with product (count)= A*B/C
5 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
function [ out ] = triangle_wave( n )
%TRIANGLE_WAVE Summary of this function goes here
% Detailed explanation goes here
t = 4*pi/1001;
tvector = 0:t:4*pi;
for count = 1:n+1
A= -1^(count-1);
B = sin((2*(count-1)+1)*tvector);
C = (2*(count-1)+1)^2;
product(count) = A*B/C;
end
for count =0:n
out = out + product(count)
end
end
I get an error in line 10. IT says subscripted assignment dimension mismatch. What does this mean?
0 commentaires
Réponse acceptée
Plus de réponses (1)
Adam
le 6 Déc 2016
Modifié(e) : Adam
le 6 Déc 2016
It means that
size( product(count) )
does not evaluate to the same thing as
size( A*B/C )
so trying to assign the latter into the former gives a dimension mismatch. product doesn't appear to be predefined anywhere so unless A*B/C results in a scalar this will not work.
e.g. the following code, in a completely clean workspace gives this error too:
a(9) = [3; 4];
because a does not exist and therefore a(9) will be assumed to be scalar if it were to be created at this moment. [3; 4] obviously is not scalar.
a(9) = 3;
works fine and creates a row vector of 8 zeros preceding the 3;
If you are trying to assign multiple dimensions to a result then you should have multiple dimensions on the left-hand side of the = also in general.
Voir également
Catégories
En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!