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

  • Home
  • SEARCH
  • 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

Ask A Question

Stats

  • Questions 335k
  • Answers 335k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Probably much easier to use XmlDocument , or XDocument. XmlDocument:… May 14, 2026 at 3:40 am
  • Editorial Team
    Editorial Team added an answer I finally figured out a way to have singularities graphed… May 14, 2026 at 3:40 am
  • Editorial Team
    Editorial Team added an answer If you're writing a touchscreen application, all you have to… May 14, 2026 at 3:40 am

Related Questions

I am having some problems with a few queries using Linq to NHibernate. These
I am having a few problems with Dojo Filtering Selects when using the Zend
Recently I have been studying recursion; how to write it, analyze it, etc. I
So I am using FCKeditor and the problem I am having is that when
I have been trying to tackle this problem , but I am having difficulty

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.