Borrar filtros
Borrar filtros

Converting arrayfun to loop

1 visualización (últimos 30 días)
Zachary Holmes
Zachary Holmes el 7 de Sept. de 2016
Respondida: Walter Roberson el 8 de Sept. de 2016
So in this code,
function cipher_text = vigenere_cipher(origionalText,key)
Array = Operator;
key = lower(key) - double('a') + 1; %Converts all text to lowercase
key(key < 0) = 27;
origionalText = lower(origionalText) - double('a') + 1;
origionalText(origionalText < 0) = 27;
keyLength = rem(0:(numel(origionalText)-1), numel(key))+1; %Converst the key to the length of the origional text
k = key(keyLength);
% Encrypt: C(n) = V(k(n), plaintext(n))
cipher_text = arrayfun(@(m,n) Array(m,n), k, origionalText) - 1;
cipher_text(cipher_text == 26) = double(' ') - double('a');
cipher_text = upper(char(cipher_text + double('a')));
end
i want to change:
cipher_text = arrayfun(@(m,n) Array(m,n), k, origionalText) - 1;
cipher_text(cipher_text == 26) = double(' ') - double('a');
cipher_text = upper(char(cipher_text + double('a')));
to a for loop. How would i do that?
  1 comentario
Walter Roberson
Walter Roberson el 8 de Sept. de 2016
How does this differ from http://www.mathworks.com/matlabcentral/answers/302182-how-to-convert-arrayfun-to-for-loop#comment_389765 in which you said that you got the code working, in response to someone else who asked about converting the same code to a for loop?

Iniciar sesión para comentar.

Respuestas (1)

Walter Roberson
Walter Roberson el 8 de Sept. de 2016
A = arrayfun( @(p,q) B(m,n), C, D);
can be converted to
A = zeros(size(C));
for idx = 1 : numel(C)
A(idx) = B( C(idx), D(idx) );
end
Except that this code does not correctly account for the possibility that a data type other than double is being returned.

Categorías

Más información sobre MATLAB en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by