store the for result to txt file using dlmwrite

조회 수: 1 (최근 30일)
Khairul nur
Khairul nur 2021년 1월 14일
편집: Walter Roberson 2021년 1월 18일
hi, i have trouble to save the list_total into the txt file as i using the dlmwrite. Eventhough this code no error but the txt file only saved the final total. The txt file shoud has list of 'total' and fews rows such as:
0 1.23 2.25 3.45 4.46 5.56
0 3.23 4.25 5.45 6.46 7.56
for c1=i:loop_col_utk_data
disp('here')
j=1
for c2=j:noofrow_centroid %6 kali run
noofrow_centroid
total=0
while j<noofrow_centroid
nilai1=centroid{j,i}
centroid{j,noofcol_centroid_innerloop}
hasiltambah=nilai1+(centroid{j,noofcol_centroid_innerloop})
j=j+1
total=total+hasiltambah
list_total(j)=total
dlmwrite('result_hasil_tambah.txt',list_total(1,j),'delimiter','\t')
end
end
i=i+1
% noofcol_centroid_innerloop=noofcol_centroid_innerloop+1
end

채택된 답변

Walter Roberson
Walter Roberson 2021년 1월 14일
편집: Walter Roberson 2021년 1월 14일

you need the -append flag to dlmwrite and you need to write in full rows, not one element at a time.

  댓글 수: 2
Khairul nur
Khairul nur 2021년 1월 18일
can you give me some example?
Walter Roberson
Walter Roberson 2021년 1월 18일
편집: Walter Roberson 2021년 1월 18일
for c1=i:loop_col_utk_data
disp('here')
list_total = zeros(1, noofrow_entroid);
for c2=1:noofrow_centroid %6 kali run
noofrow_centroid
total=0
for j = 1 : noofrow_centroid
nilai1=centroid{j,i}
centroid{j,noofcol_centroid_innerloop}
hasiltambah=nilai1+(centroid{j,noofcol_centroid_innerloop})
total=total+hasiltambah
list_total(j)=total
end
end
dlmwrite('result_hasil_tambah.txt', list_total, '-append', 'delimiter','\t')
i=i+1
% noofcol_centroid_innerloop=noofcol_centroid_innerloop+1
end

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Text Files에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by