double indexed variable (new user)
显示 更早的评论
I am very new to Matlab. I am trying to create ixj number of variables using the function below. I am getting an error message for pos(i,j) = [b/2+partsize/2+(i-1)*(b+partsize), b/2+partsize/2+(j-1)*(b+partsize)] line. How do I create indexed variables that I can call later in Matlab? Here pos(i,j)==> 1x2 vector (x and y coordinates) e.g I expect to obtain something like the following: pos (1,1)= [ 2 2] pos ( 1,2) = [2 4] pos ( 2,1) = [4 2] pos (2, 2) = [4 4] etc.
function b= posgen(cellsize, particleno, partsize)
partnoline =(particleno)^(1/2);
b= (cellsize-partnoline*partsize)/partnoline;
for i=1:partnoline;
for j=1:partnoline;
pos(i,j) = [b/2+partsize/2+(i-1)*(b+partsize), b/2+partsize/2+(j-1)*(b+partsize)]
end
end
What am I doing wrong? Can you help please
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!