Operations on 3d array without using for loop
이전 댓글 표시
I am trying to write the following code without for loops
gf_k = gf(0:3,2); % gf is a Galois-field matlab function
gf_a = gf(a, 2); % gf is a Galois-field matlab function
for i = 1 : l
for j = 1 : h
for k = 0 : 3
c = gf_k.x(k+1) + gf_a.x(i,j); % As both gf_k and gf_a are GF(4) variables, Value of c is between any of 0,1,2,3
D(i,j,k+1) = B(i,j,k+1) + A(i,j,c+1);
end
end
end
I tried using sub2ind but I couldn't get right.
댓글 수: 5
Bruno Luong
2023년 9월 4일
편집: Bruno Luong
2023년 9월 4일
"I am trying to write the following code without for loops"
Why people obcessing with removing loops. This is insane.
Furthermore such statement of function calling in general cannot be vectorized when inside the loops
c = func1(k) + func2(a(i,j))
SHRAVAN GARLAPATI
2023년 9월 4일
편집: SHRAVAN GARLAPATI
2023년 9월 4일
William Rose
2023년 9월 4일
SHRAVAN GARLAPATI
2023년 9월 4일
Bruno Luong
2023년 9월 4일
This line of code is perhaps wrong
c = gf_k.x(k+1) + gf_a.x(i,j);
it adds two double and not GF(4) elements.
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 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!