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

3 views (last 30 days)
Arin Dutta on 30 Oct 2020
Edited: Ameer Hamza on 30 Oct 2020
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);

Ameer Hamza on 30 Oct 2020
Edited: Ameer Hamza on 30 Oct 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)