write cell array of tables to a .txt file

2 views (last 30 days)
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
David Hill
David Hill on 22 Apr 2021
Edited: David Hill on 22 Apr 2021
You verified your out is a 1x30 cell array? Try reading the cell that you wrote.
out=readcell('out.txt');%should get the same thing you saved.
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)

Categories

Find more on Tables in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!