필터 지우기
필터 지우기

Script for CSV processing

조회 수: 6 (최근 30일)
Antonio Jayena
Antonio Jayena 2015년 3월 23일
댓글: dpb 2015년 3월 23일
Hi friends.
First of all I apologize for my bad English.
I tell you my problem. I was working with an osciloscope and I take around 500 measures (Voltage/Time) in CSV files. The signal is a pulse train with only the 1% of the period crossing the zero.I want to measure with matlab, for each csv, which is the value of x axis (time) for exactly 25 pulses of the whole train.
Doing this with cursors is a very hard work. I'm trying to build a Script. My main idea (because of the small time that the signal cross the zero) is to make a FOR loop, with a IF loop inside that, when Y axis have crossed the zero 25 times, the script catchs the value of the X axis in a new variable. This operation, with the bucle, for all the CSV files.
This is my idea, but Im new in Matlab and is costing me a lot.
Anyone can help me? Thank you very much.
  댓글 수: 1
Antonio Jayena
Antonio Jayena 2015년 3월 23일
Im trying to go in other way, but I'm faling in the sintax
j=1
i=1
for i=1:30
s=csvread('scope_0_1.csv',2,0);
if (r2==0) % when signal cross zero
j=j+1
else
if (j==25) % finding the 25th zero crossing
disp('s');
j=0;
i=i+1;
end
Any help plis?

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

답변 (2개)

dpb
dpb 2015년 3월 23일
s=csvread('yourfile.csv'); % read the signal
ix=find([0 diff(s>0)==1,25); % locate first 25 zero crossings
The above works by turning the input signal into a 0/1 pulse train, then looks for the positive crossing locations (where the 0 turns to 1 is a +1 difference).
The ix index vector is the position in the original vector of those crossings, specifically it will be the index of the first positive location after the zero-crossing.

Antonio Jayena
Antonio Jayena 2015년 3월 23일
Im trying to go in other way, but I'm faling in the sintax
j=1
i=1
for i=1:30
s=csvread('scope_0_1.csv',2,0);
if (r2==0) % when signal cross zero
j=j+1
else
if (j==25) % finding the 25th zero crossing
disp('s');
j=0;
i=i+1;
end
Any help plis?
  댓글 수: 3
Antonio Jayena
Antonio Jayena 2015년 3월 23일
I´m trying but I get errors.
Error using horzcat
Dimensions of matrices being concatenated are not
consistent.
Error in Matlab (line 2)
ix=find([0 diff(s>0)==1,25]);
Mi CSV has 2 colums (voltage and time)...is here my error? I make a loop because I have a lot of CSV files, and Im triying to get the value of each one printing in each iteration with
disp('s')
Thank you for your effort.
dpb
dpb 2015년 3월 23일
OK, I presumed a row vector in s; for a Nx2 array then for the voltage column it would be
ix=find([0; diff(s(:,1)>0)==1,25]);
again assuming the data array is s; obviously use whatever you use in your script.
For processing multiple files, you might look at the File Exchange function filefun that applies a function "automagically" to each function. It's at <Apply a function to files>

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

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by