how to fill pre allocated matrix using two columns vectors

Matrix = zeros(5)
interval range =10
X = [ 35;43;22]
Y = [75;44;67]
40
50
Y 60
70
80
10 20 30 40 50
X - axis
how to fix these values inside the above grid using matlab coding.
i have tried a lot using for loops but its not comming correct.
All cooperation is highly appreicated.
Regards

댓글 수: 1

It is unclear as to what you are attempting.
What is the expected output of your code ?

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

 채택된 답변

Andrei Bobrov
Andrei Bobrov 2019년 6월 26일
xx = 10:10:50;
yy = 40:10:80;
X = [ 35;43;22];
Y = [75;44;67];
m = numel(xx);
n = numel(yy);
out = zeros(m,n);
x10 = 10*floor(X/10);
y10 = 10*floor(Y/10);
[~,ii] = ismember(x10,xx);
[~,jj] = ismember(y10,yy);
out(sub2ind([m,n], ii, jj)) = 1;

댓글 수: 3

Thanks you so much Mr Andrei Bobrov. God bless you. Warm regards.
Thanks for giving me input,. i have done it succesfully.
Could you plz guide me how to only label the interior part of the object using same techniqure.
Same question but only need the interior part to be labelled as 2 or 1.
i will be very thankful.
warm regards
This is wrong.
ii, jj, and kk are INDEXES not SUBSCRIPTS. So for a larger data set, would fall out of range

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

추가 답변 (2개)

KSSV
KSSV 2019년 6월 26일
X = [ 35;43;22] ;
Y = [75;44;67] ;
[X,Y] = meshgrid(X,Y);
madhan ravi
madhan ravi 2019년 6월 26일
% Illustration
Matrix = zeros(5);
X = (10:10:50).'; % column vectors
Y = (40:10:80).';
Matrix(end,:) = X.';
Matrix(:,1) = Y

댓글 수: 5

X = [ 35;43;22]
Y = [75;44;67]
Mr. Ravi, how will we fill X and y in this grid that you have designed
plz help
Mr. Ravi, Matrix = zeros(5). it will give us zeros matrix.
i want to fill the X and y vectors values inside the Matrix using matlab coding.
Show how your result should look like?
M.S. Khan
M.S. Khan 2019년 6월 26일
편집: madhan ravi 2019년 6월 26일
results will be like this:
Honestly, how are the certain fields yellow?

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

카테고리

도움말 센터File Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

질문:

2019년 6월 26일

댓글:

2020년 4월 28일

Community Treasure Hunt

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

Start Hunting!

Translated by