Info

This question is closed. Reopen it to edit or answer.

Matching array dimensions when importing csv

1 view (last 30 days)
Ted Baker
Ted Baker on 20 Apr 2020
Closed: MATLAB Answer Bot on 20 Aug 2021
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.

Answers (0)

Community Treasure Hunt

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

Start Hunting!