How to deal the points on matrix with specific width size using Matlab?

조회 수: 1 (최근 30일)
M.S. Khan
M.S. Khan 2020년 6월 8일
댓글: M.S. Khan 2020년 6월 8일
Hi Matlab community members,
i am using this code to fill or label as '1' in the matrix with respect to width size as 10
So if the ii and jj indexes are present, the number 1 will be filled. its good.
But i need help how to deal that matrix where only zeros are present.
i want to fill that grid only as '0'. I tried to use if else statement but could not succed.
Will be very thankful for guidance and help.
regards,
xx = -40:10:40;
yy = -40:10:40;
Boundary_x = 10*floor(Slice_x/10);
Boundary_y = 10*floor(Slice_y/10);
[~,ii]=ismember(Boundary_x,xx);
[~,jj] = ismember(Boundary_y,yy);
Result_matrix(sub2ind([Size_x,Size_y],ii,jj))=1;
  댓글 수: 2
KSSV
KSSV 2020년 6월 8일
VEry confusing. Question is not clear. Can you show with one working example?
M.S. Khan
M.S. Khan 2020년 6월 8일
Hi KSSV, see the last line i.e. Result_matrix shows that matrix having numbers within width =10 with respect to ii and jj will be assigned 1.
Bu If if there was no number exist with respect to width = 10 using ii and jj, how the result_matrix will be.

댓글을 달려면 로그인하십시오.

답변 (1개)

KSSV
KSSV 2020년 6월 8일
If you know the dimensions of the Result_matrix you can initialize it either zeros or NaNs or ones. Depending on your requirement.
m = 10 ; % number of rows
n = 10 ; % number of columns
P = zeros(m,n) ; % all m*n zeros
Q = NaN(m,n) ; % all m*n NaNs
R = ones(m,n) ; % all m*n ones
  댓글 수: 1
M.S. Khan
M.S. Khan 2020년 6월 8일
i dont want to initialize it. i have alrady intialize it as zeroes (m,n).
Suppose i have a matrix with different numbers.
i want them to distribute those numbers in each grid with respect to width size as 10.
if any numbers exist, that cells will be labelled as 1 in the result_matrix.
My problem is if there is no number coming in cell with width size =10, then how the cells of the result_matrix would be.
Thanks for feedback.
i am trying to make an example.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Images에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by