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 685835
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T01:57:46+00:00 2026-05-14T01:57:46+00:00

I am having some problems comparing the elements in different cell arrays. The context

  • 0

I am having some problems comparing the elements in different cell arrays.

The context of this problem is that I am using the bwboundaries function in MATLAB to trace the outline of an image. The image is of a structural cross section and I am trying to find if there is continuity throughout the section (i.e. there is only one outline produced by the bwboundaries command).

Having done this and found where the is more than one section traced (i.e. it is not continuous), I have used the cornermetric command to find the corners of each section.

The code I have is:

%% Define the structural section as a binary matrix (Image is an I-section with the web broken)
bw(20:40,50:150) = 1;
bw(160:180,50:150) = 1;
bw(20:60,95:105) = 1;
bw(140:180,95:105) = 1;

Trace = bw;
[B] = bwboundaries(Trace,'noholes'); %Traces the outer boundary of each section

L = length(B); % Finds number of boundaries
if L > 1
    disp('Multiple boundaries') % States whether more than one boundary found
end

%% Obtain perimeter coordinates
for k=1:length(B) %For all the boundaries
    perim = B{k}; %Obtains perimeter coordinates (as a 2D matrix) from the cell array
end

%% Find the corner positions
C = cornermetric(bw);

Areacorners = find(C == max(max(C))) % Finds the corner coordinates of each boundary

[rowindexcorners,colindexcorners] = ind2sub(size(Newgeometry),Areacorners)
% Convert corner coordinate indexes into subcripts, to give x & y coordinates (i.e. the same format as B gives)

%% Put these corner coordinates into a cell array
Cornerscellarray = cell(length(rowindexcorners),1); % Initialises cell array of zeros
for i =1:numel(rowindexcorners)
    Cornerscellarray(i) = {[rowindexcorners(i) colindexcorners(i)]};
    %Assigns the corner indicies into the cell array
    %This is done so the cell arrays can be compared
end

for k=1:length(B) %For all the boundaries found
    perim = B{k}; %Obtains coordinates for each perimeter
    Z = perim; % Initialise the matrix containing the perimeter corners

    Sectioncellmatrix = cell(length(rowindexcorners),1);
    for i =1:length(perim)
        Sectioncellmatrix(i) = {[perim(i,1) perim(i,2)]};
    end

    for i = 1:length(perim)
        if Sectioncellmatrix(i) ~= Cornerscellarray
            Sectioncellmatrix(i) = [];
            %Gets rid of the elements that are not corners, but keeps them associated with the relevent section
        end
    end
end

This creates an error in the last for loop. Is there a way I can check whether each cell of the array (containing an x and y coordinate) is equal to any pair of coordinates in cornercellarray? I know it is possible with matrices to compare whether a certain element matches any of the elements in another matrix. I want to be able to do the same here, but for the pair of coordinates within the cell array.

The reason I don’t just use the cornercellarray cell array itself, is because this lists all the corner coordinates and does not associate them with a specific traced boundary.

  • 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-14T01:57:47+00:00Added an answer on May 14, 2026 at 1:57 am

    Many-to-many comparisons cannot be done with the equal sign. You need to use ismember instead.

    %# catenate all corners in one big corner array
    Cornerscellarray = cat(1,Cornerscellarray{:});
    
    %# loop through each section cell and remove all that is not corners
    for i = 1:length(perim)
         %# check for corners
         cornerIdx = ismember(Sectioncellmatrix{i},Cornerscellarray,'rows');
    
         %# only keep good entries
         Sectioncellmatrix{i} = Sectioncellmatrix{i}(cornerIdx,:);
    end
    

    Also, this code really looks like it could be a bit optimized. For example, you could use bwlabel to label your arrays, read the label with the corner coordinates to associate corners with the features.

    Like so:

    bw(20:40,50:150) = 1;
    bw(160:180,50:150) = 1;
    bw(20:60,95:105) = 1;
    bw(140:180,95:105) = 1;
    
    %# get corners
    cornerProbability = cornermetric(bw);
    cornerIdx = find(cornerProbability==max(cornerProbability(:)));
    
    %# Label the image. bwlabel puts 1 for the first feature, 2 for the second, etc.
    %# Since concave corners are placed just outside the feature, grow the features 
    %# a little before labeling
    bw2 = imdilate(bw,ones(3));
    labeledImage = bwlabel(bw2);
    
    %# read the feature number associated with the corner
    cornerLabels = labeledImage(cornerIdx);
    
    %# find all corners that are associated with feature 1
    corners_1 = cornerIdx(cornerLabels==1);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having some problems with the PDF files that I make using the
I'm having a problem with some T-SQL in a SP on SQLServer 2005 comparing
I'm having some problems while using PDO. It all seems correct but I am
I'm having some problems with Code::Blocks, and this is the output after / while
So I'm having issues with some code that I've inherited. This code was building
Some time ago, I read that comparing version numbers can be done using the
I'm having problems using {% ifequal s1 some text %} to compare strings with
I certainly don't know how to title this question, sorry. I'm having some problems
So I have a .cpp file that uses OpenCV. I've been having some problems
I'm having some problems with g++ and the compiling process for a C/C++ program

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.