word = input("Type a scrambled string: ", 's');
len = length(word)
totalPoss = factorial(len)
divisions = totalPoss/len
space = zeros(totalPoss,len);
%disp(space);
for i = 1:len
for j = 1:divisions
space((j + len*(i-1)),1) = word(i);
end
end
disp(space);
When I run the above code in a Linux environment using octave, I expect to see the array space's firec column to be filled with the letters of the input, word.
For example, if the input were to be "lime," I would expect that space[1:6][1] to be "l," space[7:12][1] to be "i," etc. Instead, this is the output I am getting:
Type a scrambled string: lime
len = 4
totalPoss = 24
divisions = 6
108 0 0 0
108 0 0 0
108 0 0 0
108 0 0 0
105 0 0 0
105 0 0 0
105 0 0 0
105 0 0 0
109 0 0 0
109 0 0 0
109 0 0 0
109 0 0 0
101 0 0 0
101 0 0 0
101 0 0 0
101 0 0 0
101 0 0 0
101 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
I am unsure as to why the first three characters are only being inserted 4 times and why all of the extra spaces are at the bottom of the array. (I also don't know why the letters are ascii numbers, but that is a different problem I think).

 Réponse acceptée

James Tursa
James Tursa le 12 Juil 2016
Modifié(e) : James Tursa le 12 Juil 2016
You defined space as a double array:
space = zeros(totalPoss,len);
That is why it is printing as ASCII values. Try this instead:
space = repmat(' ',totalPoss,len);

Plus de réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by