I'm getting an error in the line with product (count)= A*B/C
2 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
採用された回答
その他の回答 (1 件)
Adam
2016 年 12 月 6 日
編集済み: Adam
2016 年 12 月 6 日
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.
参考
カテゴリ
Help Center および File Exchange で Loops and Conditional Statements についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!