Problem saving cell to txt file

2 ビュー (過去 30 日間)
monkey_matlab
monkey_matlab 2015 年 11 月 19 日
編集済み: monkey_matlab 2015 年 11 月 19 日
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 件)

カテゴリ

Help Center および File ExchangeWorkspace Variables and MAT-Files についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by