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 ?

 채택된 답변

Adam Danz
Adam Danz 2020년 5월 1일

1 개 추천

vals = {s(1:end).name};

댓글 수: 5

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 2020년 5월 1일
편집: Adam Danz 2020년 5월 1일
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 2020년 5월 2일
Thank you very much ! resolved

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

추가 답변 (0개)

카테고리

질문:

2020년 5월 1일

댓글:

2020년 5월 2일

Community Treasure Hunt

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

Start Hunting!

Translated by