Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: Removing a location from a vector.
Replies: 4   Last Post: Mar 25, 2013 3:54 PM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
dpb

Posts: 8,164
Registered: 6/7/07
Re: Removing a location from a vector.
Posted: Mar 24, 2013 9:50 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

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.

--




Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.