Matlab takes in wrong data in command window

조회 수: 4 (최근 30일)
hi  hey
hi hey 2017년 6월 12일
댓글: Image Analyst 2017년 6월 13일
[fname, pname] = uigetfile('*.csv'); %ask for file
filename= fullfile(pname, fname); %file as string
assert(exist(filename, 'file')==2,'%s does not exist.', filename); %check if file exist
data = csvread(filename, 1) % reads data from file skipping headers
***************************Excel Data***************
(just need to shift values to according heading, they are in order)(there are like 55,000 rows but these are the first couple)
Latitude Longitude Elevation (metres) Distance (KMs) Gradient
30.6183 -96.33631 103.7 0 0
30.61832 -96.33629 103.6 0.003 0
30.61845 -96.3361 102.8 0.026 0
30.61845 -96.33608 102.7 0.028 0
**************************Data from Matlab************************
0.0363 -0.1203 0.1592 2.7105 0
0.0363 -0.1203 0.1595 2.7105 0
0.0363 -0.1203 0.1595 2.7106 0
0.0363 -0.1203 0.1578 2.7106 -0.0010
0.0363 -0.1203 0.1571 2.7107 -0.0020
  댓글 수: 5
Image Analyst
Image Analyst 2017년 6월 12일
편집: Image Analyst 2017년 6월 12일
He meant to attach your CSV file, NOT a screenshot. Please attach a CSV file that demonstrates the problem so we can replicate it.
What's showing in the Excel screenshot is not the kind of CSV file that MATLAB likes. It should be just numbers, not numbers and text with some rows of numbers having different numbers of columns than other rows.
hi  hey
hi hey 2017년 6월 12일
I have matlab skip over the headers.

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

채택된 답변

Image Analyst
Image Analyst 2017년 6월 13일
The data from MATLAB is the same, it's just that when you echo it to the command window, the data is multiplied by 1e-3. If you use fprintf() instead of just letting it automatically echo to the screen, you'll see they are the same (I tried it).
  댓글 수: 11
hi  hey
hi hey 2017년 6월 13일
편집: hi hey 2017년 6월 13일
Yep,I found it. It was line 46885 in matlab. Ok thank you all for helping me!
format shortG at the top and the textread fixed the issue
Image Analyst
Image Analyst 2017년 6월 13일
You can see in dpb's post that both csvread() and textread() have the same numbers, they're just formatted differently in the display. csvread has the 1.0e+03 in there whereas text read doesn't. But internally, in your code, using the arrays from either function will give you the same result. If you echo to the command line, the 1.0e+03 just scrolled off the top of the command window, like Walter and I said, but it's still the same numbers. So I'd use csvread() (if you have a recent version where you can tell it to skip a header line) since textread() is deprecated.

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

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by