Hi all
I have a structure that one of its fields has n members, and I want to write them to an Excel in one column in rows. trying to convert this field to array,
doing :
vals = [s(1:end).name]
instead of giving me :
vals= ['a', 'b', 'c', ..]
gave:
vals= ['abcde,...']
how do I correct it ?

 Réponse acceptée

Adam Danz
Adam Danz le 1 Mai 2020
vals = {s(1:end).name};

5 commentaires

thank you , well it creates separate cells with names of the files in the directory I want : I do this
ac={files(:).name} is doing the same thing as what you proposed. but doing the following , I will have one row written in excel, and each letter in one cell !
files=dir('*.xlsx');
ac={files(:).name}
files= cell2mat(ac)
for k = size(files): -1 : 1
if strcmp(files(k),'s1.xlsx') || strcmp(files(k),'f1.xlsx')
files(k)=[];
end
end
files
xlswrite('filenames.xlsx', files, 1)
ac={files(:).name}
% files= cell2mat(ac) % I'm not sure why you're using this line
files = ac;
% if you want to reverse the order of files,
files = flipud(files); % or fliplr(files)
% for k = size(files): -1 : 1
for k = 1:numel(files)
if strcmp(files{k},'s1.xlsx') || strcmp(files{k},'f1.xlsx')
files(k)=[]; % What does this do?
end
end
I don't see where you're writing to Excel
ok, I want to read the names of the files in a directory, actually : WITHOUT their extension.
ac={files(:).name}
% files= cell2mat(ac) % I'm not sure why you're using this line > cause dir makes a structure with 6 fields
%containing the files dates of creation , volumn etc. try it
files = ac;
% if you want to reverse the order of files,
files = flipud(files); % or fliplr(files)
% for k = size(files): -1 : 1
for k = 1:numel(files)
if strcmp(files{k},'s1.xlsx') || strcmp(files{k},'f1.xlsx')
files(k)=[]; % What does this do? because I need to drop the above 2 file names
end
end
%at the end I wanted an array of filenames without their extensions
Adam Danz
Adam Danz le 1 Mai 2020
Modifié(e) : Adam Danz le 1 Mai 2020
content = dir(. . . . . .);
content([content.isdir]) = []; % remove directories
filenames = cell(size(content));
% Extract the filename without the extentions
for i = 1:numel(files)
[~, filenames{i}] = fileparts(content(i).name);
end
farzad
farzad le 2 Mai 2020
Thank you very much ! resolved

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur File Operations dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by