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:
vectorize this part 2

Subject: vectorize this part 2

From: Marios Karaoulis

Date: 31 Jan, 2012 20:29:20

Message: 1 of 2

Hi all


I have 3 vectors mesh.x_centers, mesh.y_centers, mesh.z_centers,
defying some 3D ponts on a mesh.

I need to check each of these points, in which are they belong. This
area is defined in another matrix, mesh.param_i, where column 4 and 5
show the x's (from-to), column 7-8 the ys and column 9-10 the zs.

Is any other more efficient way to program this? The find command is
rather slow.

%now find which elements belong to each parameter
mesh.jtmp=zeros(10000,mesh.num_param);
for i=1:mesh.num_param

    % start with x's
    ind1=find(mesh.x_centers>=mesh.param_i(i,4));
    ind2=find(mesh.x_centers<=mesh.param_i(i,5));
    ind_x=intersect(ind1,ind2);

        % start with y's
    ind1=find(mesh.y_centers>=mesh.param_i(i,6));
    ind2=find(mesh.y_centers<=mesh.param_i(i,7));
    ind_y=intersect(ind1,ind2);

        % start with z's
    ind1=find(mesh.z_centers>=mesh.param_i(i,8));
    ind2=find(mesh.z_centers<=mesh.param_i(i,9));
    ind_z=intersect(ind1,ind2);


    ind=intersect(ind_x,ind_y);
    ind=intersect(ind,ind_z);

    mesh.jtmp(1:length(ind),i)=ind;

end

Subject: vectorize this part 2

From: Bruno Luong

Date: 1 Feb, 2012 11:58:09

Message: 2 of 2

Marios Karaoulis <marios.karaoulis@gmail.com> wrote in message <c1ae45d4-9f2e-4c09-bf67-9d830aa44627@q8g2000yqa.googlegroups.com>...
> Hi all
>
>
> I have 3 vectors mesh.x_centers, mesh.y_centers, mesh.z_centers,
> defying some 3D ponts on a mesh.
>
> I need to check each of these points, in which are they belong. This
> area is defined in another matrix, mesh.param_i, where column 4 and 5
> show the x's (from-to), column 7-8 the ys and column 9-10 the zs.
>
> Is any other more efficient way to program this? The find command is
> rather slow.
>
> %now find which elements belong to each parameter
> mesh.jtmp=zeros(10000,mesh.num_param);
> for i=1:mesh.num_param
>
> % start with x's
> ind1=find(mesh.x_centers>=mesh.param_i(i,4));
> ind2=find(mesh.x_centers<=mesh.param_i(i,5));
> ind_x=intersect(ind1,ind2);
>
> % start with y's
> ind1=find(mesh.y_centers>=mesh.param_i(i,6));
> ind2=find(mesh.y_centers<=mesh.param_i(i,7));
> ind_y=intersect(ind1,ind2);
>
> % start with z's
> ind1=find(mesh.z_centers>=mesh.param_i(i,8));
> ind2=find(mesh.z_centers<=mesh.param_i(i,9));
> ind_z=intersect(ind1,ind2);
>
>
> ind=intersect(ind_x,ind_y);
> ind=intersect(ind,ind_z);
>
> mesh.jtmp(1:length(ind),i)=ind;
>
> end

help tsearch

Bruno

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