How to swap data variables in particular columns

조회 수: 1 (최근 30일)
Stephen Devlin
Stephen Devlin 2017년 11월 29일
댓글: Stephen Devlin 2017년 11월 29일
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

채택된 답변

Birdman
Birdman 2017년 11월 29일
편집: Birdman 2017년 11월 29일
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
Birdman
Birdman 2017년 11월 29일
Ok, let me know the results.
Stephen Devlin
Stephen Devlin 2017년 11월 29일
perfect, thank you again

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by