Save data to file with different array size

조회 수: 1 (최근 30일)
monkey_matlab
monkey_matlab 2015년 11월 18일
댓글: Thorsten 2015년 11월 18일
Hello, I wanted to save a data file that contains different array sizes. Can you assist me with this task? This is the code that I have so far:
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);
A = [a b c d e];
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',A');
fclose(fileID);
  댓글 수: 1
Thorsten
Thorsten 2015년 11월 18일
What should be written in lines 16 to 20, where you do not have values for a and b? Should there be zeros for a and b, or should there be only three values c, d, e, or what do you want?

댓글을 달려면 로그인하십시오.

답변 (1개)

Meghana Dinesh
Meghana Dinesh 2015년 11월 18일
When you execute A = [a b c d e]; don't you get an error? The dimensions of a, b, c, d & e aren't consistent. You cannot concatenate them. Try using cell. Each cell can contain any type of data. Or just write them separately into files.
  댓글 수: 2
monkey_matlab
monkey_matlab 2015년 11월 18일
Hello, I do get an error. If I use the cell approach, will I be able to save that into a file?

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by