Creating a Matrix from a nesting For loop
1 view (last 30 days)
Show older comments
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
0 Comments
Accepted Answer
Stephen23
on 13 Oct 2020
The MATLAB approach:
>> [Xm,Ym] = meshgrid(1:25,1:25);
>> Zm = Xm.*Ym;
>> surf(Xm,Ym,Zm)
Giving:
0 Comments
More Answers (0)
See Also
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!