Hi Riccardo,
Converting to strings seems inefficient to me (and it not required for this problem either).
Here is an alternative way to get the output:
N=5;
vec = [1 4 3 1]
powN = (length(vec)-1): -1: 0;
powN = N.^powN;
ans = vec*(powN');
Explanation: Generate powers of N in a vector and then dot multiply this to get your answer.
You can combine these statements if you wish to speed up your code. Try:
ans = vec*(N.^((length(vec)-1:-1:0)'));
Hope it Helps!
Best Answer