필터 지우기
필터 지우기

Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

Matching array dimensions when importing csv

조회 수: 1 (최근 30일)
Ted Baker
Ted Baker 2020년 4월 20일
마감: MATLAB Answer Bot 2021년 8월 20일
Hi I'm trying to match the dimensions of two arrays so i can plot them. One is longer than the other, so I am trying to interpolate the data to create two equal arrays. My code is as follows:
close all;
measurementfile = 'FILE1_20.csv';
backgroundfile = 'FILE1_4.csv';
% Workings
% Load both files in
filelines1 = strtrim(strsplit(fileread(measurementfile), newline()));
startstop1 = find(ismember(upper(filelines1), {'BEGIN','END'})) - [0,2];
unit1 = filelines1(16);
T1 = csvread(measurementfile, startstop1(1), 0, [startstop1(1) 0 startstop1(2) 4]);
[~,filename1,ext1] = fileparts(measurementfile);
filelines2 = strtrim(strsplit(fileread(backgroundfile), newline()));
startstop2 = find(ismember(upper(filelines2), {'BEGIN','END'})) - [0,2];
unit2 = filelines2(16);
T2 = csvread(backgroundfile, startstop2(1), 0, [startstop2(1) 0 startstop2(2) 4]);
[~,filename2,ext2] = fileparts(backgroundfile);
% Determine unit and put into variables. Create y axis label.
if contains(unit1, "! DATA UNIT dB?V" )
freq1 = T1(:,1);
measured = T1(:,2);
%%%%%%%%%
xnew = linspace(min(freq1), max(freq1), 601);
T1new = interp1(freq1, measured, xnew);
%%%%%%%%%
freq1new = T1new(:,1);
measurednew = T1new(:,2);
%%%%%%%%%%
T1new = reshape(T1new, 601,1);
T1new = [freq1new, T1new];
%%%%%%%%%%
freq2 = T2(:,1);
background = T2(:,2);
ylabelplot = "Power (dB\muV)";
end
Now T1new has the correct number of points, but doesn't come with the 4 additional columns of T2 (601x1 and 601x5 respectively). Is there a way to add the frequency column to T1new to verify the interpolation is correct - and to add the additional columns of zeros, as in T2? I've attached two example files for reference.

답변 (0개)

이 질문은 마감되었습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by