필터 지우기
필터 지우기

Reading and ploting a notepad txt file on Matlab

조회 수: 6 (최근 30일)
Mini Me
Mini Me 2012년 11월 25일
편집: Walter Roberson 2017년 3월 14일
I am trying to get the my data read through Matlab and then plot it. but with my code using fscanf and/or textscan the file is being read as one array and taking the data one by one as a character which makes it impossible to plot. It's like each char/integer is an array.here's how my data looks like:
Time Volt Chan 1 chan 2 chan 3 chan 4 chan 5 chan 6 chan7
3333.222 222.33 0.2334 0.3444 0.2233 0.4455 -0.733 0.3333 0.123
3333.222 0.2323 0.4566 0.3456 0.2453 0.4563 -0.753 0.2356 0.233
I want to plot the time data Versus the volts and the other channels separately. Can Anyone help? I know the data looks wrong on here but There's two set of data for each channels.
  댓글 수: 2
Walter Roberson
Walter Roberson 2012년 11월 25일
What arguments did you you use for textscan() when you tried?
Mini Me
Mini Me 2012년 11월 26일
편집: Walter Roberson 2017년 3월 14일
i use that general form:
filename=input('input filename','%s')
fid=fopen(filename,'r')
array=fscanf(fid,%e%c, [,inf]
plot(array([1],:),array([3],:))
fclose(fid)
and then plot. but I can never get it to read the file right and keep in mind that these are not the acual arguments inside the functions.

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

답변 (4개)

moulay
moulay 2012년 11월 25일
save the data as .txt data. with the load function load filname.txt. befor you do this, you shold comment the title line (the first line. (strg+r)).
now you do this:
% load filename.txt
time=filename(:,1);
volt=filename(:,2);
chanel1=filename(:,3);
and so on.....
plot(time,volt)

Mini Me
Mini Me 2012년 11월 26일
That did not work at all because the file is tab delimited. and I want to plot the time column to the volt column and so on..

Mini Me
Mini Me 2012년 11월 26일
And how do you comment the first line, because before i took the first line out by using fget(fid) is there another way with your code
  댓글 수: 1
moulay
moulay 2012년 11월 26일
do you have just one file to open?
Comment a line: put at the begining of the line %

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


Mini Me
Mini Me 2012년 11월 27일
Never mind I fixed it. Thanks for the help but I went with a different approach
  댓글 수: 1
Vanessa Wen
Vanessa Wen 2014년 5월 22일
May I know your approach as I face the same problem as you.

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

카테고리

Help CenterFile Exchange에서 Standard File Formats에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by