Problem with dlmwrite writeing a tensor in a csv file

Hi guys,
I need to save a tensor in a file..I'm using this solution:
n=268;
m=4381;
d=7;
dati_orig=zeros(n,m,p);
for i=1:n
for j=1:m
for k=1:p
dati_orig(i,j,k)=dati_copia(i,j,k);
end
end
end
fid2 = fopen('dati_orig.csv','w');
for k=1:p
ele=xmat_orig(:,:,k);
dlmwrite('dati_orig.csv', ele, '-append' )
dlmwrite('dati_orig.csv', ' ' ,'-append' )
end
fclose(fid2);
where dati_copia is the tensor to save. The tensor must to be wrote in the file in this manner:
1 2 3 \\ % \\ is equal to \n newline 4 5 6 \\ 7 8 9 \\ %a blank row 10 11 12 \\ 13 14 15 \\ 16 17 18 \\ ......
This code works fine because with a small tensor it's ok. But I'm writing a tensor of dimensions 268x4381x7 and between each slice there is not a blank line as I want. The csv file must to have 1888 lines but the file has only 1882 rows. Can someone help me? Is it the wrong code? Thanks. giuseppe

답변 (2개)

Amit
Amit 2014년 1월 25일
편집: Amit 2014년 1월 25일
Try this:
% fid2 = fopen('dati_orig.csv','w');
for k=1:p
% ele=xmat_orig(:,:,k);
dlmwrite('dati_orig.csv', dati_orig(:,:,k), '-append' )
dlmwrite('dati_orig.csv', ' ' ,'-append' )
end
% fclose(fid2);
BTW, if you're trying to save dati_copia, why copy it again exactly the same. Also, what is xmat_orig because this is what you're writing in the csv file in your code.
giuseppe
giuseppe 2014년 1월 26일
편집: giuseppe 2014년 1월 26일

0 개 추천

Hi,
there is an error of tensor name! I try with the new code but it is the same of my old code! For example: row 269 is blank and it is ok..but row 539 is not blank! giuseppe

댓글 수: 1

Amit
Amit 2014년 1월 26일
편집: Amit 2014년 1월 26일
Doesn't row 538 is suppose to be blank!
Also, please write your responses as comments and not as a new answer.

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

카테고리

제품

질문:

2014년 1월 25일

편집:

2014년 1월 26일

Community Treasure Hunt

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

Start Hunting!

Translated by