MATLAB Answers

0

how to fill pre allocated matrix using two columns vectors

Asked by M.S. Khan on 26 Jun 2019
Latest activity Commented on by M.S. Khan on 17 Jul 2019
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 Comment

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

Sign in to comment.

3 Answers

Answer by Andrei Bobrov
on 26 Jun 2019
 Accepted Answer

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;

  2 Comments

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

Sign in to comment.


Answer by KSSV
on 26 Jun 2019

X = [ 35;43;22] ;
Y = [75;44;67] ;
[X,Y] = meshgrid(X,Y);

  0 Comments

Sign in to comment.


Answer by madhan ravi
on 26 Jun 2019

% Illustration
Matrix = zeros(5);
X = (10:10:50).'; % column vectors
Y = (40:10:80).';
Matrix(end,:) = X.';
Matrix(:,1) = Y

  5 Comments

Show how your result should look like?
results will be like this:
Honestly, how are the certain fields yellow?

Sign in to comment.