How can I write the name of file into entry of matrices?
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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)

2 comentarios
Walter Roberson
el 28 de Mayo de 2021
Somehow @Frisda Sianipar duplicated the question word for word in https://www.mathworks.com/matlabcentral/answers/841640-how-to-write-the-name-of-file-into-entry-of-matrices
Respuestas (1)
Jonas
el 27 de Mayo de 2021
Editada: Jonas
el 27 de Mayo de 2021
you can't save numbers and strings on the same matrix, if you want to do that use a cell array. to achieve this use e.g.
D{k,1}=...
it is recommended to initialize the whole cell array before you assign values to the individual cells (using the cell() command)
0 comentarios
Ver también
Categorías
Más información sobre Matrix Indexing en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!