hello, I have sevral of colums vector with different sizes, and I want to write them all to a csv file,in the following way:
for example, vec1=[11,12,13,14], vec2=[21,22,23]; vec3=[31,32,33,34,35,36] the output should be something like this:
line1: 11, 21,31line2: 12, 22,31line3: 13, 23,32line4: 14, ,34line5: , ,35line6: , ,36
but instead the output is like this:
11,21,3112,22,3213,23,3314,343536
the code:
vec1=[11,12,13,14]; vec2=[21,22,23]; vec3=[31,32,33,34,35,36]; vec=[]; for i=1:max([length(vec1),length(vec2),length(vec3)]) if (i<=length(vec1)) vec=[vec,vec1(i)]; else vec=[vec,[]]; end if (i<=length(vec2)) vec=[vec,vec2(i)]; else vec=[vec,[]]; end if (i<=length(vec3)) vec=[vec,vec3(i)]; else vec=[vec,[]]; end dlmwrite('test.csv', vec,'-append'); vec=[]; end
I tried replacing "vec=[vec,[]]" in the else with "vec=[vec,NaN]", and it worked, but I dont want to see "NaN" at all in the csv file. is there any other way to keep it blank? for record, I do not know in advance the length of each vector.
Best Answer