Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 630565
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T19:52:08+00:00 2026-05-13T19:52:08+00:00

I am having some problems with the find function in MATLAB. I have a

  • 0

I am having some problems with the find function in MATLAB. I have a matrix consisting of zeros and ones (representing the geometry of a structural element), where material is present when the matrix element = 1, and where no material is present when the matrix element = 0. The matrix may have the general form shown below (it will update as the geometry is changed, but that isn’t too important).

                 Geometry = [0 0 0 0 0 0 0 0 0 0;
                             0 0 1 0 1 0 1 1 0 0;
                             0 0 1 0 0 0 0 1 0 0;
                             0 0 1 0 0 0 0 0 0 0;
                             0 0 0 0 0 0 0 1 0 0;
                             0 0 0 0 0 0 0 0 0 0;
                             0 0 1 0 0 0 0 1 0 0;
                             0 0 1 0 0 0 0 1 0 0;
                             0 0 1 1 1 1 0 1 0 0;
                             0 0 0 0 0 0 0 0 0 0;]

I’m trying to find the the rows and columns that are not continuously connected (i.e. where the row and columns are not all equal to 1 between the outer extents of the row or column) and then update them so they are all connected. I.e. the matrix above becomes:

                Geometry =  [0 0 0 0 0 0 0 0 0 0;
                             0 0 1 1 1 1 1 1 0 0;
                             0 0 1 0 0 0 0 1 0 0;
                             0 0 1 0 0 0 0 1 0 0;
                             0 0 1 0 0 0 0 1 0 0;
                             0 0 1 0 0 0 0 1 0 0;
                             0 0 1 0 0 0 0 1 0 0;
                             0 0 1 0 0 0 0 1 0 0;
                             0 0 1 1 1 1 1 1 0 0;
                             0 0 0 0 0 0 0 0 0 0;]

The problem I am having is I want to be able to find the indices of the first and last element that is equal to 1 in each row (and column), which will then be used to update the geoemtry matrix.

Ideally, I want to represent these in vectors, so going across the columns, find the row number of the first element equal to 1 and store this in a vector called rowfirst.

I.e.:

                    rowfirst = zeros(1,numcols)
                    for i = 1:numcols % Going across the columns
                    rowfirst(i) = find(Geometry(i,1) == 1, 1,'first') 
                                       % Store values in vector called rowfirst
                    end

and the repeat this for the columns and to find the last elements in each row.

For some reason, I can’t get the values to store properly in the vector, does anyone have an idea of where I’m going wrong?

Thanks in advance. Please let me know if that isn’t clear, as I may not have explained the problem very well.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T19:52:08+00:00Added an answer on May 13, 2026 at 7:52 pm

    Ok, I can spot two mistakes:

    • You should use an array as the first argument of find. So, if you want to find the row number of the first element of each column, then you should use find(Geometry(:, i), 1, 'first').

    • Find returns an empty array if the column contains only zeros. You should handle this case and decide what number you want to put into rownumber (e.g. you can put -1, to indicate that the corresponding column contains no non-zero elements).

    Following the above, you can try this:

    for i = 1:numcols
      tmp = find(Geometry(:, i), 1, 'first');
      if(tmp)
        rowfirst(i) = tmp;
      else
        rowfirst(i) = -1;
      end;
    end;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been having some problems trying to get my PHP running. When I
I'm having some problems with a datagridview element I'm using in VS2008. This DataGridView
I'm having some problems integrating MS MapPoint 2009 into my WinForms .Net 2.0 application
I'm having some problems with the ranking used by fulltext search in SQL Server.
I'm having some problems getting my object to gracefully fail out if an invalid
I'm having some problems with the following code: private class ClientPluginLoader : MarshalByRefObject {
I'm having some problems with my WCF server and client connections. If I use
I'm having some problems displaying the contents of one NSArrayController in two windows defined
I am currently having some problems with <li> in IE6 essentially my code looks
I'm having some minor problems with some animations I'm trying to set up. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.