Creating a Matrix from a nesting For loop

1 Ansicht (letzte 30 Tage)
Andrew Steetz
Andrew Steetz am 13 Okt. 2020
Beantwortet: Stephen23 am 13 Okt. 2020
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

Akzeptierte Antwort

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

Weitere Antworten (0)

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Produkte


Version

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by