how to creat Multiplication table
조회 수: 6 (최근 30일)
이전 댓글 표시
I'm trying to creat a multiplication table for the following
f=[5:.332:55];
omegahz=(2*pi)*f;
amp=0:0.01:1.5;
My attempt was
f=[5:.332:55];
omegahz=(2*pi)*f;
amp=0:0.01:1.5;
for n=1:151
omegan =omegahz(1,n)
ampn= amp(1,n)
g(ampn,omegan)=ampn*omegan
end
so I think I have to call on the location not the value so I tried this
f=[5:.332:55];
omegahz=(2*pi)*f;
amp=0:0.01:1.5;
for n=1:151
omegan =omegahz
ampn= amp
g(ampn,omegan)=ampn.*omegan
end
and get this
??? Subscript indices must either be real positive integers or logicals.
Error in ==> Untitled3 at 10
g(ampn,omegan)=ampn.*omegan
I'm Not sure how to proceed on this one, Your help Is appreciated. Thanks
댓글 수: 0
채택된 답변
Matt Fig
2012년 11월 15일
편집: Matt Fig
2012년 11월 15일
I am not quite sure if this is what you want, but have a look at this:
A = 1:5;,
B = 1:10;
C = bsxfun(@times,A,B.') % Also try bsxfun(@times,A.',B)
The error you got is easy to understand. You cannot index into an array with anything but a nonpositive integer or logical. Think about it. Consider this array:
A = [10 11 12];
What is the first element? A(1) is 10. What is the second element? A(2) is 11. What about the third element? A(3) is 12. So what element is A(2.23)? NONE.
댓글 수: 3
Matt Fig
2012년 11월 17일
Bob, did you look at the output of my code? Why are you trying to use BSXFUN on two scalar values? x and y are both scalars, but BSXFUN is for vectors.
If 'test' is the array you want, and you already can get it, what is your question about? Are you looking for this:
ac = bsxfun(@times,a(1:n),w2(1:n).'); % Not in a loop!
You need to explain what you want at the end, given those inputs.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!