MATLAB Answers

write cell array of tables to a .txt file

6 views (last 30 days)
ITgirl
ITgirl on 22 Apr 2021
Commented: ITgirl on 22 Apr 2021
I'm new to matlab so i'm sorry if my question might sound easy.
I have a cell array in which each cell contains a table of different size(all tables have 2 columns but have different number of rows). I want to save the first column of every table in this cell (which is a string but without the quotation mark) in a text file in a way that each ROW of this file is a column of my tables seperated with tab. I've tried writecell and writetable and fprintf; but couldn't get it done. how can I do this?
here is how my cell looks like:
and here is one of the tables:
I want the output to be like this and so on for every table in a single text file:
YAL017W YAL028W YBL049W ...
Thanks in advance

Accepted Answer

David Hill
David Hill on 22 Apr 2021
out=[]
for k=1:length(yourCell)
out=[out,strjoin(yourCell{k}.Var1,'\t')];
end
  7 Comments
ITgirl
ITgirl on 22 Apr 2021
Yes it's a 1*30 cell. This writes cell in one line too.
THANK YOU SO MUCH for your time and help.
This solved my problem and has 30 lines:
fileID = fopen('out.txt','wt');
fprintf(fileID,'%s\n',out{:});
fclose(fileID)

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!

Translated by