How to write the name of file into entry of matrices?
조회 수: 1 (최근 30일)
이전 댓글 표시
I want to write the name of some pictures as a entry of a matrices
i have code like this:
myFolder = uigetdir;
filePattern = fullfile(myFolder, '*.jpg');
theFiles = dir(filePattern);
BanyakGambar=length(theFiles)
for k = 1 : BanyakGambar
baseFileName = theFiles(k).name;
fullFileName = fullfile(theFiles(k).folder, baseFileName);
fprintf(1, 'running %s\n', baseFileName);
D(k,1)=k;
s=string(baseFileName);
D(k,2)=s; %This line is the problem!!
end
but why the name of the pictures can't display in matrices D, and i got this result for matrices D
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/632840/image.png)
i expect the result is like this (manually write in excel). Thankyou in advance
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/632845/image.png)
답변 (1개)
Walter Roberson
2021년 5월 27일
편집: Walter Roberson
2021년 5월 28일
You cannot do that. It is never possible to store a string() or character vector into a numeric object.
You need to use a cell array or struct or table()
댓글 수: 2
Walter Roberson
2021년 5월 28일
word = {'hello'; 'Frisda'}
number = [86; 99]
as_cell = [word, num2cell(number)]
as_table = table(word, number)
as_struct = struct('word', word, 'number', number)
참고 항목
카테고리
Help Center 및 File Exchange에서 Text Analytics Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!