0

我创建的这个 Matlab 函数基本上采用泰克示波器生成的 csv 文件并绘制两个通道的信号。但是,创建的每个测试和 csv 文件都有不同的点数(在这种情况下是9999,意思是 [ B16:B10014])和 Excel( tek0001ALL) 中工作表的不同名称。我是 matlab 新手,这可能不是最好的代码效率方法,所以我想知道是否有一种更简单的方法来生成通用代码,可以绘制任何生成的 csv,以检测填充的最后一个单元格这些列和单元格的数量,因此它也可以是点数,因为有时需要执行大量测试。

function [ Vs1, Vs2, t ] = scope![enter image description here][1]( filename )

% Read the Y axis data of the scope data in volts CH1
Vs1 = xlsread(filename, 'tek0001ALL', 'B16:B10014');
% Read the Y axis data of the scope data in volts CH2
Vs2 = xlsread(filename, 'tek0001ALL', 'C16:C10014');
% Read the sample interval from the scope data in seconds
sample_interval = xlsread(filename, 'tek0001ALL', 'B7');
% Create time axis
t = 0:sample_interval:(9999*sample_interval)-sample_interval;

%Plot waveform
figure
subplot(2,1,1);
plot(t,Vs1);
title('Sensor Input Measurements for 100pc Discharge ');
xlabel('Time[s]');
ylabel('Voltage[V]');
grid on;
grid minor;

subplot(2,1,2);
plot(t,Vs2);
title('Sensor Output Measurements for 100pc Discharge');
xlabel('Time[s]');
ylabel('Voltage[V]');
grid on;
grid minor;

end

CSV 文件格式的示例如下:

Model,DPO3034
Firmware Version,1.08

Point Format,Y,
Horizontal Units,S,
Horizontal Scale,8e-07,
Sample Interval,8e-10,
Record Length,10000,
Gating,0.0% to 99.9900%,0.0% to 99.9900%
Probe Attenuation,1,1
Vertical Units,V,V
Vertical Offset,0,0
Vertical Scale,0.05,0.001
Label,,
TIME,CH1,CH2
-1.4664e-06,-0.003,-0.00036
-1.4656e-06,-0.003,-0.00036
-1.4648e-06,-0.003,-0.00036
-1.4640e-06,-0.001,-0.00032
-1.4632e-06,-0.003,-0.00036
-1.4624e-06,-0.001,-0.00036
-1.4616e-06,-0.001,-0.0004
-1.4608e-06,-0.003,-0.00036
4

1 回答 1

1

如果您将数据保留在 CSV 文件中,您可以使用csvread这很容易。

function [ Vs1, Vs2, t ] = scope( filename )

%Read csv with 15 header rows
data = csvread(filename, 15);

t = data(:,1);
Vs1 = data(:,2);
Vs2 = data(:,3);

%Plot waveform
figure
    subplot(2,1,1);
        plot(t,Vs1);
        title('Sensor Input Measurements for 100pc Discharge ');
        xlabel('Time[s]');
        ylabel('Voltage[V]');
        grid on;
        grid minor;

    subplot(2,1,2);
        plot(t,Vs2);
        title('Sensor Output Measurements for 100pc Discharge');
        xlabel('Time[s]');
        ylabel('Voltage[V]');
        grid on;
        grid minor;

end
于 2015-07-21T21:19:47.050 回答