Building a matrix inside a for loop

8 ビュー (過去 30 日間)
faiber vargas
faiber vargas 2021 年 5 月 3 日
コメント済み: Cris LaPierre 2021 年 5 月 7 日
Hello guys I am new programming on matlab and I was trying to build a matrix using a for cycle but I could´t .
I made this code:
clc
clear
syms x
P=5
for i=1:0.5:P
for j=1:0.5:P
x=[ i j;]
end
end
but that code doesn't build a matrix, the matrix that a need is like this :
X = [-1.5 3.2; 1.8 3.3; -3.7 1.5; -1.5 1.3;
0.8 1.2; 3.3 1.5; -2 -1.0;-2.3 -0.7;
0 -0.5; 2.0 -1.5; 3.7 -0.8; -3.5 -2.9;
-0.9 -3; 2.0 -3; 3.5 -2.25]
it's a matrix of points or coodinates, that will be used to make a voronoi diagram but we want to make the points with a matrix due the numbers of pints varie between 50 and 1000 and it will be longer if I write it and also uneffiecient.
So how I have to write the for cycle to build that matrix with the coordinates of the points? as I need.
I would appreciate your help
  2 件のコメント
David Hill
David Hill 2021 年 5 月 3 日
I have no idea based on your code on how you expect to get your desired output. What is the relationship between 1:.5:5 and your output?
faiber vargas
faiber vargas 2021 年 5 月 3 日
I want a point every 0.5 until 20 or 100, and that is because we want to represent a micrography with voronoi diagram that will be create with those points in the matrix . so we represents the micrography with the voronoi diagram and later we simulate its behavior.

サインインしてコメントする。

回答 (1 件)

Cris LaPierre
Cris LaPierre 2021 年 5 月 3 日
  2 件のコメント
faiber vargas
faiber vargas 2021 年 5 月 6 日
Sorry I try it, but it doesn't work.
Cris LaPierre
Cris LaPierre 2021 年 5 月 7 日
What have you tried? What isn't working?
If I run the example I linked to, the result is a 10x10 matrix.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeVoronoi Diagram についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by