Problem saving cell to txt file

3 次查看(过去 30 天)
Hello, I am trying to save different size arrays to a text file. Can you help me save my arrays to the text file?
Here is my code:
clc;clear;
A = (0.5)*rand(15,1);
B = (0.5)*rand(15,1);
C = (0.5)*rand(20,1);
D = (0.5)*rand(20,1);
E = (0.5)*rand(20,1);
outA = num2cell(A);
outB = num2cell(B);
outC = num2cell(C);
outD = num2cell(D);
outE = num2cell(E);
Arows = size(outA);
fileID = fopen('check.txt','w');
for row = 1:Arows;
fprintf(fileID, '%6f,\r\n' ,outA{row,:});
end
fclose(fileID);
%CELL = {[outA] [outB] [outC] [outD]};
CELL = [{outA} {outB} {outC} {outD} {outE}];
% fileID = fopen('check.txt','w');
% fprintf(fileID,'%6s %6s %6s %6s %6s\r\n','a','b', 'c', 'd', 'e');
% fprintf(fileID,'%6.5f %6.5f %6.5f %6.5f %6.5f\r\n',CELL);
% fclose(fileID);

采纳的回答

John Petersen
John Petersen 2015-11-19
The error is telling you that you can't use cells in your print function. That's because cell arrays can be different lengths, as you have tried to do. It's like trying to convert different size cell arrays into a matrix -- it doesn't work because a matrix needs all the columns to have the same number of rows.

更多回答(0 个)

标签

Community Treasure Hunt

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

Start Hunting!

Translated by