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

 採用された回答

Stephen23
Stephen23 2020 年 10 月 13 日

0 投票

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeLoops and Conditional Statements についてさらに検索

製品

リリース

R2019a

質問済み:

2020 年 10 月 13 日

回答済み:

2020 年 10 月 13 日

Community Treasure Hunt

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

Start Hunting!

Translated by