필터 지우기
필터 지우기

Change Precision of numbers when saving in csvwrite

조회 수: 44 (최근 30일)
Katy Weihrich
Katy Weihrich 2018년 3월 24일
댓글: Walter Roberson 2018년 3월 26일
I want to save some data that has one data line which is quite long (e.g.: Data = [12345678, -3.53, 1.52, -0.23; 12345679, -1.43, 6.12, 8.12; 12345680, -0.01, -5.12, -6.13; ...]). I really need the precision of the last digit, but when I use csvwrite the number is cut to 12,345,700. after some searching I found following solution:
csvwrite(FileName, Data, 'precision', '%i')
and it worked at first, but for some reason it stoped working now, which is very confusing to me.
Every time it just gives me an:
Error using csvwrite (line 47)
Invalid attribute tag: ,.
Is there maybe another way I can do it?
  댓글 수: 4
Katy Weihrich
Katy Weihrich 2018년 3월 26일
I am using Matlab R2017a and I get
/opt/gridware/apps/binapps/matlab/R2017a/toolbox/matlab/iofun/csvwrite.m
as a reply to
which csvwrite -all
But I am not quite sure how the directory is helpful?
Katy Weihrich
Katy Weihrich 2018년 3월 26일
I tried some different versions with csvwrite and dlmwrite:
dlmwrite(YourFileName, A, 'delimeter', ',', 'precision', '%i')
csvwrite(YourFileName, A, 'delimeter', ',', 'precision', '%i')
dlmwrite(YourFileName, A, 'precision', '%i')
csvwrite(YourFileName, A, 'precision', '%i')
the first gives me an "Error using dlmwrite (line 104). Invalid attribute tag: delimeter.", the secound an "Error using csvwrite. Too many input arguments.", the third a "Error using dlmwrite (line 116). Cannot open file " and the last a "Error using csvwrite (line 47). Invalid attribute tag: ,." I also tried replacing the '%i' with numbers, but it did not change anything. When I only use csvwrite(YourFileName, A) or dlmwrite(YourFileName, A) i get an "cannot open file" error as well.

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

채택된 답변

Walter Roberson
Walter Roberson 2018년 3월 25일
You are passing 'precision' as your row value, and '%i' as your column value to csvwrite(). csvwrite() then thinks it is passing those to dlmwrite(). dlmwrite() is noticing that they are named options for the purposes of dlmwrite() and is parsing them.
However, there is a bug in current dlmwrite in that if any of the named options are provided then the positional options are not recognized. This is contrary to the dlmwrite documentation and I will file a bug report about that.
I will not, however, file a bug report about csvwrite() because you are misusing it. You should not be using csvwrite() for your purposes. You should be calling dlmwrite() instead
dlmwrite(YourFileName, Data, 'delimeter', ',', 'precision', '%i')
  댓글 수: 2
Katy Weihrich
Katy Weihrich 2018년 3월 26일
I am sorry, when I try this version i get an:
Error using dlmwrite (line 104)
Invalid attribute tag: delimeter.
error message.
Walter Roberson
Walter Roberson 2018년 3월 26일
dlmwrite(YourFileName, Data, 'delimiter', ',', 'precision', '%i')

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

추가 답변 (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