Operations on 3d array without using for loop
Mostra commenti meno recenti
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 Commenti
Bruno Luong
il 4 Set 2023
Modificato: Bruno Luong
il 4 Set 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
il 4 Set 2023
Modificato: SHRAVAN GARLAPATI
il 4 Set 2023
William Rose
il 4 Set 2023
SHRAVAN GARLAPATI
il 4 Set 2023
Bruno Luong
il 4 Set 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.
Risposta accettata
Più risposte (0)
Categorie
Scopri di più su Loops and Conditional Statements in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!