Creating a Matrix from a nesting For loop

Hello
I am currently working on a school project and needing some assistance with syntax. New to Matlab by the way.
Basically, I am trying to set up a 3d graph that is like a multiplication table.
Id like to be set up in a way that when x=1 and y=1 then z=1. But then the x=1 is also multiplied by y=2, y=3,y=4 ... and so on (to 25). To be able to create a 3d graph however the Z-axis is supposed to be presented as a matrix. How can I create a matrix that lines up with this multiplication. Where the corners will equal 1, 25, 25, 625 respectively. And then be able to graph those values on a x,y,z
Here is what I have so far:
x=0;
y=0;
for Kx=1:25
x=1+x;
y=0;
for Ky=1:25
y=1+y;
end
end

 Respuesta aceptada

Stephen23
Stephen23 el 13 de Oct. de 2020
The MATLAB approach:
>> [Xm,Ym] = meshgrid(1:25,1:25);
>> Zm = Xm.*Ym;
>> surf(Xm,Ym,Zm)
Giving:

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.

Productos

Versión

R2019a

Preguntada:

el 13 de Oct. de 2020

Respondida:

el 13 de Oct. de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by