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!