I a writting a script that will create and display a cell array that will loop to store strings of lengths 4, 5, 6, and 7. it will ask the user for the string and also make a error-check. for example:
Enter a string of length 5: helloEnter a string of length 6: !@#$%^
ncell{2} =helloError: String has wrong lengthncell{3} =!@#$%^
Here is my code
stringlength = cell(4,1); n = 4;for i = n:7 stringlength{i} = input('Enter a string of length :','s') if length(stringlength) ~= i disp('Enter the right one') else stringlength{i} = input('Enter a string of length :','s') end end
However, the code seems wrong because it keeps going although I put in a wrong length of strings
Best Answer