Invalid expression. Check for missing multiplication operator, missing or unbalanced delimiters, or other syntax error. To construct matrices, use brackets instead of parentheses.

1 visualización (últimos 30 días)
In the following code, out = cryptoshift(in, shift) : while using a sting in the in argument and shift this by an integer value, it shows the error "Invalid expression. Check for missing multiplication operator, missing or unbalanced delimiters, or other syntax error. To construct matrices, use brackets instead of parentheses." How to solve this?
function out = cryptoshift('ABC',5 )
numbers = double(lower(in))-96;
codednumbers = zeros(1,length(numbers));
for i = 1:length(numbers);
if numbers(i) >= 1 & numbers(i) <= 26
codednumbers(i) = mod(numbers(i)+shift-1,26)+1;
else
codednumbers(i) = numbers(i);
end
end
out = char(codednumbers+96);

Respuestas (1)

Ameer Hamza
Ameer Hamza el 30 de Oct. de 2020
Editada: Ameer Hamza el 30 de Oct. de 2020
In MATLAB, the input argument in the function definition must be variables. You are writing constant values. Change the function definition to the following
function out = cryptoshift(in, shift) % <--- use variable names here
numbers = double(lower(in))-96;
codednumbers = zeros(1,length(numbers));
for i = 1:length(numbers)
if numbers(i) >= 1 & numbers(i) <= 26
codednumbers(i) = mod(numbers(i)+shift-1,26)+1;
else
codednumbers(i) = numbers(i);
end
end
out = char(codednumbers+96);
end
and then call it like this
cryptoshift('ABC', 5)

Categorías

Más información sobre Encryption / Cryptography en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by