Problem saving cell to txt file

2 vues (au cours des 30 derniers jours)
monkey_matlab
monkey_matlab le 19 Nov 2015
Modifié(e) : monkey_matlab le 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);

Réponse acceptée

John Petersen
John Petersen le 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.

Plus de réponses (0)

Catégories

En savoir plus sur Workspace Variables and MAT-Files dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by