フィルターのクリア

How to solve Index out of bounds because numel(A)=4

1 回表示 (過去 30 日間)
U B
U B 2021 年 2 月 12 日
コメント済み: KSSV 2021 年 2 月 12 日
My aim is to generate the intensity profile for the output light passing through a polariser and an analyser for different angles of analyser . I am cosidering a gaussian light beam.
gaussian function-
function H = my_gaussian(n, sigma)
two_sigma_sq = 2*sigma*sigma;
H = zeros(n);
for i = 1:n
for j = 1:n
x = i - n/2;
y = j - n/2;
H(i,j) = exp(-(x*x + y*y)/two_sigma_sq);
end
end
end
Intensity profile-
H = my_gaussian(256, 50) ;
Ph = 0; E1 = cosd(Ph); E2 = sind(Ph);
E = [E1 ; E2];
Th = [0 30 90];
for i = 1:length(Th)
A11 = cosd(Th(i))*cosd(Th(i));
A12 = cosd(Th(i))*sind(Th(i));
A21 = cosd(Th(i))*sind(Th(i));
A22 = sind(Th(i))*sind(Th(i));
A = [A11, A12; A21, A22]
O = A(i)*E
I = O'*O
IP = I*H;
figure, imshow(IP);axis image;colorbar;
end
I can put maximum 3 values of Th, it gives me correct answer but as soon as I put 4 values, the 4th value is Incorrect. If I try putting more than 4 values error comes up saying
" Attempted to access A(5); index out of bounds because numel(A)=4.
Error in Untitled2 (line 31)
O = A(i)*E "
What should I change in this program?
  1 件のコメント
KSSV
KSSV 2021 年 2 月 12 日
What inputs you have tried? The given code now workd fine.

サインインしてコメントする。

採用された回答

KSSV
KSSV 2021 年 2 月 12 日
This line:
O = A(i)*E ;
should be changed to:
O = A*E
  2 件のコメント
U B
U B 2021 年 2 月 12 日
It worked. Thank you so much for your help.
KSSV
KSSV 2021 年 2 月 12 日
Thanks is accepting/ voting the aswer.. :)

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMATLAB についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by