Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations GregLocock on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Compare and replace elements in matrix

Status
Not open for further replies.

Capzos

Computer
Aug 8, 2005
7
i have a matrix which has 16 columns and varying number of rows.. i
need to replace the elements ranging from -50 to 50 with zero and the
rest should remain the same.. i have coded for a single element
search and replace which is

[m, n] = size(Data);
for i = 1: m
for j = 1:n
if ( Data(i,j) == 1 )
Data(i,j) = 0;
end
end
end

but how do i do it for a range of -50 to 50 instead of a 1 in my
code.. could anyone help me out.. also please suggest me if there are
any matlab function which does this with out the use of the for
loops...
Regards,
capzos
 
Replies continue below

Recommended for you

it isnt a homework.. i am trying some stuff out... which i want to implement completly in matlab with as less number of loops as possible making the complete use of matlab inbuilt function.. but its so vast to read... so i am posting some of the general issues that i come trough.. help me if u could

i think i found the soln for this.. but help me in future
thanks
 
I don't do Matlab, but... Matlab should be capable of doing something like this:

if ( Data(i,j) >= -50 AND Data(i,j) <= 50 )
Data(i,j) = 0;

Dan :)
dan@dtware.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor