I'm getting an error in the line with product (count)= A*B/C
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuesta aceptada
Más respuestas (1)
Adam
el 6 de Dic. de 2016
Editada: Adam
el 6 de Dic. de 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.
Ver también
Categorías
Más información sobre Loops and Conditional Statements 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!