How do I ask for a string input?

13 visualizaciones (últimos 30 días)
Hakob Enfiajyan
Hakob Enfiajyan el 7 de Oct. de 2022
Comentada: Star Strider el 9 de Oct. de 2022
n=input("Number of files: ");
for i=1:n
FileName(i) = input("File Name: ","s");
Here is my code which ends up giving me an error message saying
I'm simply asking for a string and inputting it into FileName which should hold all the string
Unable to perform assignment because the indices on the left side are not compatible with the size of the right side.
Error in DataReader (line 6)
FileName(i) = input("File Name: ","s");
What am I doing wrong? Just 20 minutes ago my code was working perfectly fine

Respuesta aceptada

Star Strider
Star Strider el 7 de Oct. de 2022
It is likely easier to save it to a cell array —
FileName{i} = input("File Name: ","s");
That worked when I tried it offline.
See Access Data in Cell Array if you are unfamiliar with cell arrays.
.
  4 comentarios
Hakob Enfiajyan
Hakob Enfiajyan el 9 de Oct. de 2022
There's maybe some type of bug. Thank you for the inputdlg idea, I did it again using that and it worked perfectly.
Star Strider
Star Strider el 9 de Oct. de 2022
As always, my pleasure!
It also leaves the Command Window free, another reason I prefer it.

Iniciar sesión para comentar.

Más respuestas (0)

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by