Operations on 3d array without using for loop
Show older comments
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 Comments
Bruno Luong
on 4 Sep 2023
Edited: Bruno Luong
on 4 Sep 2023
"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
on 4 Sep 2023
Edited: SHRAVAN GARLAPATI
on 4 Sep 2023
William Rose
on 4 Sep 2023
SHRAVAN GARLAPATI
on 4 Sep 2023
Bruno Luong
on 4 Sep 2023
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.
Accepted Answer
More Answers (0)
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!