How to write the name of file into entry of matrices?

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
i expect the result is like this (manually write in excel). Thankyou in advance

5 件のコメント

Frisda Sianipar
Frisda Sianipar 2021 年 5 月 28 日
Yes, he is my lecturer
Walter Roberson
Walter Roberson 2021 年 5 月 28 日
編集済み: Walter Roberson 2021 年 5 月 28 日
Lecturers should not need to post requests for help in solving an assignment.
And I do mean word for word identical. Except for the final "thank you". Not just the problem set, but identical words of description.
Frisda Sianipar
Frisda Sianipar 2021 年 5 月 28 日
okay sir

サインインしてコメントする。

回答 (1 件)

Walter Roberson
Walter Roberson 2021 年 5 月 27 日
編集済み: Walter Roberson 2021 年 5 月 28 日

0 投票

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 件のコメント

Frisda Sianipar
Frisda Sianipar 2021 年 5 月 28 日
Can you give some example to do that sir?
Walter Roberson
Walter Roberson 2021 年 5 月 28 日
word = {'hello'; 'Frisda'}
word = 2×1 cell array
{'hello' } {'Frisda'}
number = [86; 99]
number = 2×1
86 99
as_cell = [word, num2cell(number)]
as_cell = 2×2 cell array
{'hello' } {[86]} {'Frisda'} {[99]}
as_table = table(word, number)
as_table = 2×2 table
word number __________ ______ {'hello' } 86 {'Frisda'} 99
as_struct = struct('word', word, 'number', number)
as_struct = 2×1 struct array with fields:
word number

サインインしてコメントする。

カテゴリ

ヘルプ センター および File Exchange で Structures についてさらに検索

質問済み:

2021 年 5 月 27 日

コメント済み:

2021 年 5 月 28 日

Community Treasure Hunt

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

Start Hunting!

Translated by