Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Removing a location from a vector.

Subject: Removing a location from a vector.

From: Skylar

Date: 24 Mar, 2013 20:50:26

Message: 1 of 5

I am making comparisons between three different vectors, testing to see if the data at these given locations is the same.

Here is the program so far:

Tot_Press = find(suture2(:,3)<60|suture2(:,3)>70); %This finds which batches exceed or do not meet the pressure req.
p=length(Tot_Press);
Press_Per=p/26;

Tot_Temp = find(suture2(:,2)<150|suture2(:,2)>170); %This finds which batches exceed or do not meet the temp req.
t=length(Tot_Temp);
Temp_Per=t/26;

Tot_DT = find(suture2(:,4)<2.0|suture2(:,4)>2.5); %This finds which of the batches exceed or do not meet the dwell time req.
d=length(Tot_DT);
DT_Per=d/26;

for i=0:26
    if (Tot_Press(i) == Tot_Temp(i)) | (Tot_Press(i) == Tot_DT(i))
        
    else
        if (Tot_Temp(i) == Tot_DT(i))
            
        end

As you see I have made the comparisons, but I am curious as to if there is a function to delete certain locations from the vectors without having to create another vector and store all data that is not equal into it.

Thanks for the help.

Subject: Removing a location from a vector.

From: dpb

Date: 24 Mar, 2013 23:50:38

Message: 2 of 5

On 3/24/2013 3:50 PM, Skylar wrote:
> I am making comparisons between three different vectors, testing to see
> if the data at these given locations is the same.
...

doc ismember
doc intersect

and friends may be of interest....

--

Subject: Removing a location from a vector.

From: Nasser M. Abbasi

Date: 25 Mar, 2013 00:25:07

Message: 3 of 5

On 3/24/2013 2:50 PM, Skylar wrote:

>
> As you see I have made the comparisons, but I am curious as to if
>there is a function to delete certain locations from the vectors
>without having to create another vector and store all data that is not equal into it.
>
> Thanks for the help.
>

Are you saying, for example, given A a vector of 10
elements, and you want to "delete" the second element
of this vector, but want keep the same vector as is, still
with 10 elements (but now with the second element "deleted"
from it) so to avoid making a new vector, say B, of 9 elements
and copy those 9 elements from A to B and delete the
memory occupied by A?

Is this what you are asking?

Just trying to understand the question first.

--Nasser

Subject: Removing a location from a vector.

From: dpb

Date: 25 Mar, 2013 01:50:32

Message: 4 of 5

On 3/24/2013 3:50 PM, Skylar wrote:
> I am making comparisons between three different vectors, testing to see
> if the data at these given locations is the same.
>
> Here is the program so far:
>
> Tot_Press = find(suture2(:,3)<60|suture2(:,3)>70); %This finds which
...

>
> Tot_Temp = find(suture2(:,2)<150|suture2(:,2)>170); %This finds which
...

>
> Tot_DT = find(suture2(:,4)<2.0|suture2(:,4)>2.5); %This finds which of
...

>
> for i=0:26
> if (Tot_Press(i) == Tot_Temp(i)) | (Tot_Press(i) == Tot_DT(i))
> else
> if (Tot_Temp(i) == Tot_DT(i))
> end

Not sure what you want as end result but several problems here--first,
Matlab arrays are _always_1-based so the above loop will fail on the
first iteration w/ index out of bounds.

Next, the result of each separate find() may well be a different
length--it would seem only by rare happenstance that wouldn't be so.
So, you would need to account for that.
>
> As you see I have made the comparisons, but I am curious as to if there
> is a function to delete certain locations from the vectors without
> having to create another vector and store all data that is not equal
> into it.

How about using the helper function I posted recently...

function flg=iswithin(x,lo,hi)
   % Logical T if x between lo and hi, inclusive
   flg = (x>=lo) & (x<=hi);

ixPr = ~iswithin(suture2(:,3),60,70);
ixT = ~iswithin(suture2(:,2),150,170);
ixDT = ~iswithin(suture2(:,4),2.0,2.5);

Now you have three logical vectors of the same length as the original
array but with T (ones) where the condition in each is so. NB the ~ to
negate the inclusive within test to get the opposite of your test.

With that you can then find which are true collectively by simply
writing the expression

ixAll = all([ixPr ixT ixDT],2);

which will be a logical (column) vector of the same length but T only
where each of the three conditions you've tested for is simultaneously T.

Again, not sure where you're headed, but hopefully that gives some
ideas. Note that to get the values you then simply can write
expressions like

S=suture2(ixAll,:);

to get the full dataset (all columns) for the rows found.

--

Subject: Removing a location from a vector.

From: dpb

Date: 25 Mar, 2013 19:54:00

Message: 5 of 5

On 3/24/2013 3:50 PM, Skylar wrote:
...
With that you can then find which are true collectively by simply
writing the expression

ixAll = all([ixPr ixT ixDT],2);

which will be a logical (column) vector of the same length but T only
where each of the three conditions you've tested for is simultaneously T.

Again, not sure where you're headed, but hopefully that gives some
ideas. Note that to get the values you then simply can write
expressions like

S=suture2(ixAll,:);

to get the full dataset (all columns) for the rows found.

Or, of course, if this is an exclusion process, then perhaps you're
looking for

suture2(ixAll,:)=[];

to collapse to everything except those found above...

Salt to suit, obviously.

--

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us