MATLAB Answers

How to write a structure field to Excel?

4 views (last 30 days)
farzad
farzad on 1 May 2020
Commented: farzad on 2 May 2020
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 ?

  0 Comments

Sign in to comment.

Accepted Answer

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

  5 Comments

Show 2 older comments
farzad
farzad on 1 May 2020
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 on 1 May 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 on 2 May 2020
Thank you very much ! resolved

Sign in to comment.

More Answers (0)


Translated by