【问题标题】:How can I improve this code to import an osciloscope signal from a csv into matlab如何改进此代码以将示波器信号从 csv 导入 matlab
【发布时间】:2015-10-11 08:14:42
【问题描述】:

我创建的这个 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

【问题讨论】:

    标签: matlab csv oscilloscope


    【解决方案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
    

    【讨论】:

      猜你喜欢
      • 2020-08-08
      • 1970-01-01
      • 2022-01-13
      • 2016-12-20
      • 1970-01-01
      • 2019-02-11
      • 1970-01-01
      • 1970-01-01
      • 2014-10-14
      相关资源
      最近更新 更多