How to swap data variables in particular columns

1 Ansicht (letzte 30 Tage)
Stephen Devlin
Stephen Devlin am 29 Nov. 2017
Kommentiert: Stephen Devlin am 29 Nov. 2017
Hi,
I have a large data set of repeated tests at different frequencies, when the measuring equipment has an issue and cannot measure correctly it sometimes records the results incorrectly: num freq value ___ ___ ____
1.00 10.00 1.10
10.00 2.00 2.30
3.00 10.00 NaN
4.00 10.00 9.30
5.00 10.00 2.66
6.00 10.00 0.71
10.00 7.00 2.22
8.00 10.00 6.02
9.00 10.00 9.90
10.00 10.00 104.00
i.e. num should go smoothly from 1:10 and the frequency for this table should all be 10KHZ. Is there a simple way to swap the values which are incorrect?
close all
clear all
clc
%some fake data to illustrate issue
A=(1:10)';
B=ones(10,1)*10;
C=[1.1,2.3,NaN,9.3,2.66,0.71,2.22,6.02,9.9,104]';
data=horzcat(A,B,C);
data(2,1)=10;
data(2,2)=2;
data(7,1)=10;
data(7,2)=7;
datatab=array2table(data);
vars={'num','freq','value'};
datatab.Properties.VariableNames=vars
at the moment I am splitting the data into separate frequencies so that they are all of the same frequency in each batch using a for loop and don't know where to go from there.
Best regards
Steve

Akzeptierte Antwort

Birdman
Birdman am 29 Nov. 2017
Bearbeitet: Birdman am 29 Nov. 2017
One approach:
num=[1 10 3 4 5 6 10 8 9 10];
freq=[10 2 10 10 10 10 7 10 10 10];
ind=freq~=10;
temp1=freq(ind);
temp2=num(ind);
num(ind)=temp1
freq(ind)=temp2
Now you have it. Apply this into your problem.
  3 Kommentare
Birdman
Birdman am 29 Nov. 2017
Ok, let me know the results.
Stephen Devlin
Stephen Devlin am 29 Nov. 2017
perfect, thank you again

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by