Not getting the expected size matrix from evaluating a function handle that is equal to zero
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Nilay Modi
el 29 de Mzo. de 2024
Comentada: Nilay Modi
el 29 de Mzo. de 2024
h = @(x,y) 0
[X, Y] = meshgrid(linspace(0, 2, 10));
Z = h(X,Y);
X and Y are 10 x 10.
I am expecting Z to be zeros matrix of 10x10. But I am getting Z to be a 0 of 1x1.
Why?
0 comentarios
Respuesta aceptada
Leonardo
el 29 de Mzo. de 2024
h = @(x,y) zeros(size(x));
[X, Y] = meshgrid(linspace(0, 2, 10));
Z = h(X,Y)
surf(X,Y,Z)
0 comentarios
Más respuestas (2)
VBBV
el 29 de Mzo. de 2024
h = @(x,y) zeros(10)
[X, Y] = meshgrid(linspace(0, 2, 10));
Z = h(X,Y)
11 comentarios
Torsten
el 29 de Mzo. de 2024
Define
g = @(x,y,m,n) zeros(m,n)
in the script part
and use it as
Z = g(X,Y,size(X,1),size(X,2))
in your function.
Don't overcomplicate things - your code looks complicated enough.
Steven Lord
el 29 de Mzo. de 2024
I am expecting Z to be zeros matrix of 10x10. But I am getting Z to be a 0 of 1x1.
Why?
Because that's what you told your function to return.
Based on your later comment, you don't want your function to return a 1-by-1 or even a fixed 10-by-10. You want it to return a zeros matrix the same size as the input. Correct?
f = @(X, Y) zeros(size(X));
X = ones(4)
f(X, X)
Y = ones(5, 8)
f(Y, Y)
Z = 42
f(Z, Z)
0 comentarios
Ver también
Categorías
Más información sobre Graphics Objects en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!