Want to create an array of filenames on every row of a matrix

조회 수: 28(최근 30일)
I am looking to create an array of file names on every row of a matrix,and I keep getting
"In an assignment A(:) = B, the number of elements in A and B must be the same." or "Assignment has more non-singleton rhs dimensions than non-singleton subscripts"
This is what I have right now:
hello = 0;
for i = 1:8
str = strcat('world',' ', num2str(i))
hello(i,:) = str;

채택된 답변

Geoff Hayes
Geoff Hayes 2017년 9월 25일
Richard - you initialize hello as a scalar instead of as a matrix or cell array so this is going to lead to problems. Try doing the following instead
myFilenames = cell(8,1);
for i = 1:8
str = strcat('world',' ', num2str(i));
myFilenames{i} = str;
myFilenames =
  댓글 수: 2
Image Analyst
Image Analyst 2017년 9월 25일
Yes. No need as far as I can tell to store all the filenames. Use this:
thisFilename = sprintf('%s%d_Processed.csv', v, k);
[fieldname(k), csv] = container(folderX, thisFilename);
assuming v is a string.
And I can't see that container() is correct - I think a huge portion of it is missing and what's there is almost useless. What you have there would cause an error but not the one you mentioned. It gets data, but doesn't do anything with it, and it returns fileID and csv which it never created. Because so much code is missing, and you did not include the whole error message, just a small part of it, we can't really debug it anymore.

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

추가 답변(1개)

Stalin Samuel
Stalin Samuel 2017년 9월 25일
편집: Stalin Samuel 2017년 9월 25일
%hello = 0;
for i = 1:8
str = [strcat('world',' ', num2str(i))]
hello{i,:} = str;


Find more on プログラミング in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!