My matlab code is generating a cell of order 10000*100. I have to save all the columns of this cell in text format separately. I mean i should get 100 text files. what should i do? please help

 Akzeptierte Antwort

Ahmed Rashid
Ahmed Rashid am 2 Jun. 2016

0 Stimmen

a = rand(1000, 100);
for k = 1:100
fileID = fopen(['data', num2str(k), '.txt'],'w');
fprintf(fileID,'%f\n',a(:, k));
fclose(fileID);
end

5 Kommentare

Bhaskar panchireddi
Bhaskar panchireddi am 2 Jun. 2016
Thanks for your response. You have considered 'a' as rand(1000,100); But my file 'a' has order of m*n which is in cell format where as your 'a' is in double format. please help
Walter Roberson
Walter Roberson am 2 Jun. 2016
The first thing you should do is define the format you want the cells written out in, including any information about how you want to mark the end of one cell and the beginning of the next.
Then you just use curly brackets. Assuming that a is a cell. The code below will simply put the entries in the cells in one column. You need to provide more information in your question what format you want to have them in the text file.
for k = 1:100
fileID = fopen(['data', num2str(k), '.txt'],'w');
fprintf(fileID,'%f\n',a{:, k});
fclose(fileID);
end
Bhaskar panchireddi
Bhaskar panchireddi am 2 Jun. 2016
Thank you so much
Bhaskar panchireddi
Bhaskar panchireddi am 2 Jun. 2016
The text file is an alphanumeric one with different number of columns varying which looks like this
TABLE: "AREA AUTO MESH ASSIGNMENTS"
Area=1 MeshType="Maximum Size" MeshGroup=All Max1=1.2 Max2=1.2 LocalEdge=Yes LocalFace=No SuppEdge=Yes SuppFace=No SubMesh=No
TABLE: "AREA BRIDGE OBJECT FLAGS" Area=1 AutoBridge=Yes BridgeObj=BOBJ1 BOSpan="Span 1" CompType="Top Slab" StartSta=0 EndSta=2.7875
TABLE: "AREA LOCAL AXES ASSIGNMENTS 1 - TYPICAL" Area=1 Angle=0
and so on...
I have read these text files in matlab which are in cell format and edited the files according to the requirement. I need to save the edited files (which in cell format) in text format
Hope you understood the problem

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Tags

Noch keine Tags eingegeben.

Community Treasure Hunt

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

Start Hunting!

Translated by