How to create the contour (closed surface) utilizing matlab functions or loopings using the given Matrix under certain conditions

Question_linear_interpolation.png

6 Comments

Don't post your question as a image. Type it here or copy paste it here. What excactly you want? Your question is very confusing.
i want in each row and each column to have starting 3 and closing 3.
i mean i want to get closed boundary.
so that i can find the interior of boundary to utilize it for further calculation.
how to close the row and column if it has only one 3 but not closing 3 or vice versa
i am trying linear interpolation but its also not working
A = [ 0 0 0 0 0 0 0; 0 0 3 3 0 3 0; 0 0 0 0 0 3 0; 0 0 3 0 0 3 0; 0 3 0 0 3 0 0; 0 0 0 0 0 0 0]
What does starting and closing mean in the context of a matrix?
Guillaume, i mean for example 3 0 0 0 0 3 0. so in this row vector, starting 3 is in the first column and closing (ending) 3 is in the 6th column.
if we scan by column wise , i am looking for starting and ending 3.
similarly if i am looking row wise, then there is starting and ending 3 as well.
my objective is that all rows and columns must have starting and ending 3. if not, then how to introduce 3 in those columns or rows using matlab plateform.
thanks for anticipation
regards
Ok, that makes it a bit clearer, I still don't understand why you say that in:
[ 0 0 0 0 0 3 0]
you say that the row has a closing 3 but not starting 3. Why couldn't you say it has a starting 3 but no closing 3?
So, it looks like you want each row and column to have either no 3 at all, or at least two 3s. So for the rows/columns with just one 3, any preference where the missing 3 should be added?
i want to generate a closed surface just like a circular surface. i want to create boundary for that surface by filling 3s on the boundary.
let me make it more clear. From the below matrix, there is an ouline which is not closed, i want to close it by fillings 3s.M
[ 0 0 0 3 3 0 0 0
0 0 3 0 0 0 3 0
0 3 0 0 0 0 3 0
3 0 0 0 0 0 0 3
3 0 0 0 0 0 0 0
3 0 0 0 0 0 0 0
0 3 0 0 0 0 3 0
0 0 0 0 0 0 3 0
0 0 0 0 0 0 0 0
0 0 3 3 0 0 0 0 ]
if you see it, its some circular closed shape. i want to maintain the shape by filling the missing values of 3s in rows and columns so that i can get the interior of the shape.
Thanks and regards for advance for all help and cooperation.

Sign in to comment.

Answers (1)

I understand that you want to fill the matrix such that the boundaries are filled circularly.
And for starting 3, it should be before the middle row or column and vice-versa for the closing.
So, for say matrix:
[ 0 0 0 3 3 0 0 0
0 0 3 0 0 0 3 0
0 3 0 0 0 0 3 0
3 0 0 0 0 0 0 3
3 0 0 0 0 0 0 0
3 0 0 0 0 0 0 0
0 3 0 0 0 0 3 0
0 0 0 0 0 0 3 0
0 0 0 0 0 0 0 0
0 0 3 3 0 0 0 0 ]
You would like the output to be something like this:
[ 0 0 0 3 3 0 0 0
0 0 3 0 0 3 3 0
0 3 0 0 0 0 3 0
3 0 0 0 0 0 0 3
3 0 0 0 0 0 0 3
3 0 0 0 0 0 0 3
0 3 0 0 0 0 3 0
0 3 0 0 0 0 3 0
0 3 0 0 0 0 3 0
0 0 3 3 3 3 0 0]
You can do it by dividing the whole matrix into 4 quadrants similar to the circle.
The following code below implements it for when the number of columns is greater than number of rows.
%your matrix
a=zeros(8,10);
N=a(1,:);
M=a(:,1);
m1=N/2;
e1=m1+1;
m2=M/2;
e2=m2+1;
%for first quadrant;
j=1;
for i=m2:-1:1
if a(j,i)~=3
a(j,i)=3;
end
j=j+1;
j=min([j,m1]);
end
%for 2nd quadrant
j=e1;
for i=1:m2
if a(j,i)~=3
a(j,i)=3;
end
j=j+1;
j=min([j,N]);
end
%for 3rd quadrant
j=N;
for i=e2:M
if a(j,i)~=3
a(j,i)=3;
end
j=j-1;
j=max([j,e1]);
end
%for 4th quadrant
j=m1;
for i=M:-1:e2
if a(j,i)~=3
a(j,i)=3;
end
j=j-1;
j=max([j,1]);
end
You can the modify the above code for the case where no of rows are more than columns.

1 Comment

Thanks Dheeraj Singh. i am tryiing to apply it on different matrices of different shapes.
Regards for your reply.

Sign in to comment.

Products

Release

R2018a

Asked:

on 14 Aug 2019

Commented:

on 20 Aug 2019

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!