construct meshgrid matrices without using function meshgrid.
Afficher commentaires plus anciens
Hi, I am going to construct meshgrid matrices1 x(i, j), y(i, j), given the grid points x=[0: 0.1:10], y=[0:0.2:10]. when I try x.*y.'. It can't go through. I know I can produce an mn matrix C with elements C(i, j) = x(i)y(j), i=1:m, j= 1:n. But I dunno how can I start with.
Réponse acceptée
Plus de réponses (1)
Mert Yiyit
le 5 Déc 2018
0 votes
function [A,B] = mgrid(x,y)
m = length(x);
n = length(y);
for i= 1:n
for j= 1:m
A(i,j) = x(1,j);
end
end
for q = 1:m
for z = 1:n
B(z,q) = y(1,z);
end
end
1 commentaire
Note that the outputs A and B should be preallocated, as Image Analyst's answer from four years ago shows.
Catégories
En savoir plus sur Resizing and Reshaping Matrices dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!