how to fill pre allocated matrix using two columns vectors
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
Shashank Sharma
2019-6-26
It is unclear as to what you are attempting.
What is the expected output of your code ?
采纳的回答
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 个评论
erik jensen
2020-4-28
This is wrong.
ii, jj, and kk are INDEXES not SUBSCRIPTS. So for a larger data set, would fall out of range
更多回答(2 个)
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!