MATLAB Answers

unique function return value of duplicate vector entry

조회 수: 25(최근 30일)
vincent demunck
vincent demunck 7 Jan 2021
I'm currently using the below stated code to load and analyze a text file of IR sensor data that I gathered. I want to plot part of the IR data against the time, and localize the minima using islocalmin, this has worked so far for a great number of my data but now i'm encoutering a problem.
Upon running the code, i get the error that Sampleploints values contains duplicates (for the first entry under sensor 1) , and upon running the unique command i do indeed see that it deletes an entry from Time1_1 such that there is a doubly recorded time value. I have the same problem for the islocalmin command in the first line under sensor 2.
But i'm unable to extract exactly which timevalue (index of Time1_1 or Time2_1) is the duplicate value so that I can also delete it from V1_1 and V2_1, is there anyone that can help me with.
clc; close all; clear all;
D = readtable('0712-1064-100-IR','Filetype','text');
V1 = table2array(D(:,1));
Time1 = table2array(D(:,2));
Vminarray1 = table2array(D(:,5));
Vmintime1 = table2array(D(:,6));
V2 = table2array(D(:,7));
Time2 = table2array(D(:,8));
Vmintime2 = table2array(D(:,12));
Vminarray2 = table2array(D(:,11));
Vlin = table2array(D(:,14));
%adjusted variables Sensor 1
V1_1 = V1(1:149046);
V1_2 = V1(149047:end);
Time1_1 = Time1(1:149046);
Time1_2 = Time1(149047:end);
%adjusted variables Sensor 2
V2_1 = V2(1:149046);
V2_2 = V2(149047:end);
Time2_1 = Time2(1:149046);
Time2_2 = Time2(149047:end);
[C1,ind1] = unique(Time1_1,'last');
[C2,ind2] = unique(Time2_1,'last');
close all; clc;
Nr_droplets = 2000; %1558? (3117/2) %how to get this count? Is this something you add in after or from the video file? --> now i added t1min1 and t2min2 and divided by two and rounded down or divided ds1 or ds2 by 2
%Nr_droplets is size of LD?
%plot data to visualise it, but divid by 1e6 to go from miliseconds to seconds
%first part of the Data
title('Voltage data both sensors')
xlabel('time (s)') %sure this is in seconds?
ylabel('IR sensor signals (V)')
grid on
hold on
%plot((Vmintime1/1e6),Vminarray1, 'marker', 'x', 'linestyle' , 'none', 'Color', 'red');
%plot((Vmintime2/1e6),Vminarray2, 'marker', 'x', 'linestyle' , 'none', 'Color', 'blue');
hold off
%second part of the data
title('Voltage data both sensors')
xlabel('time (s)') %sure this is in seconds?
ylabel('IR sensor signals (V)')
grid on
hold on
%plot((Vmintime1/1e6),Vminarray1, 'marker', 'x', 'linestyle' , 'none', 'Color', 'red');
%plot((Vmintime2/1e6),Vminarray2, 'marker', 'x', 'linestyle' , 'none', 'Color', 'blue');
hold off
%adjusted variables again --> convert to seconds --> arduino registers
Time1_1s = Time1_1/1e6;
Time1_2s = Time1_2/1e6;
Time2_1s = Time2_1/1e6;
Time2_2s = Time2_2/1e6;
%find and evaluate sensor1minima - Prominence is the width of the interval
%to make sure that it only detects a single minimum in the interval and not
%multiple. --> minseperation ensures that we only detect a signle minimum
%and not multiple.
%sensor1 minima
V1min_1 = islocalmin(V1_1,'MinProminence',0.04,'MinSeparation',0.12,'SamplePoints',Time1_1s);
V1min_2 = islocalmin(V1_2,'MinProminence',0.04,'MinSeparation',0.12,'SamplePoints',Time1_2s);
%sensor2 minima
V2min_1 = islocalmin(V2_1,'MinProminence',0.04,'MinSeparation',0.12,'SamplePoints',Time2_1s);
V2min_2 = islocalmin(V2_2,'MinProminence',0.04,'MinSeparation',0.12,'SamplePoints',Time2_2s);

  댓글 수: 1

Jeremy Hughes
Jeremy Hughes 7 Jan 2021
A few notes here...
V1 = table2array(D(:,1));
is equivalent to
V1 = D.(1);
V1 = D.Var1;% (or whatever the name is).
BUT, you can also just use readvars which does all that for you.
[V1,Time1,~,~,Vminarray1,Vmintime1,V2,Time2,~,~,Vminarray2,Vmintime2,~,Vlin] = readvars('0712-1064-100-IR','Filetype','text'); % I think all the names/tildas are in the right place... but don't trust me.
As far as the actual question, you'd need to include the data file to say anything.

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


James Tursa
James Tursa 7 Jan 2021
편집: James Tursa 7 Jan 2021
Why can't you just use ind1 and ind2? E.g.,
V1_1 = V1_1(ind1);
V2_1 = V2_1(ind1);
V1_2 = V1_2(ind2);
V2_2 = V2_2(ind2);

  댓글 수: 1

vincent demunck
vincent demunck 8 Jan 2021
After Searching further I actually found the answer online in another topic by using the following bit of code below!
[v2,w2] = unique(Time2_1,'last');
duplicate_indices2 = setdiff( 1:numel(Time2_1), w2 );

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

Community Treasure Hunt

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

Start Hunting!

Translated by