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

 채택된 답변

Star Strider
Star Strider 2022년 10월 7일

0 개 추천

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

Hakob Enfiajyan
Hakob Enfiajyan 2022년 10월 8일
I'm familiary with them and that's what I ended up doing. I'm just not sure what the problem was since it worked just fine before it started glitching.
That surprised me as well, because:
str = "string"
str = "string"
whos str
Name Size Bytes Class Attributes str 1x1 150 string
k = 1;
test(k) = str
test = "string"
obviously works.
It may be something to do with how the input function works (or doesn’t work in this instance). That it apparently can’t work and play well with string inputs may be a bug. I was definitely able to reproduce the problem with giving input a string however I couldn’t find a work-around for it, other than the cell array approach.
I generally use inputdlg (that creates a cell array for the returned argument), rather than input, so I have essentially no experience with input.
.
Hakob Enfiajyan
Hakob Enfiajyan 2022년 10월 9일
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 2022년 10월 9일
As always, my pleasure!
It also leaves the Command Window free, another reason I prefer it.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

질문:

2022년 10월 7일

댓글:

2022년 10월 9일

Community Treasure Hunt

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

Start Hunting!

Translated by