Save data to file with different array size

1 view (last 30 days)
monkey_matlab
monkey_matlab on 18 Nov 2015
Commented: Thorsten on 18 Nov 2015
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 Comment
Thorsten
Thorsten on 18 Nov 2015
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?

Sign in to comment.

Answers (1)

Meghana Dinesh
Meghana Dinesh on 18 Nov 2015
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.

Categories

Find more on Cell Arrays in Help Center and File Exchange

Tags

Products

Community Treasure Hunt

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

Start Hunting!