Problem saving cell to txt file

3 visualizaciones (últimos 30 días)
monkey_matlab
monkey_matlab el 19 de Nov. de 2015
Editada: monkey_matlab el 19 de Nov. de 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);

Respuesta aceptada

John Petersen
John Petersen el 19 de Nov. de 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.

Más respuestas (0)

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by