Problem saving cell to txt file
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
monkey_matlab
am 19 Nov. 2015
Bearbeitet: monkey_matlab
am 19 Nov. 2015
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);
0 Kommentare
Akzeptierte Antwort
John Petersen
am 19 Nov. 2015
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 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Text Files finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!