在 MatLab 函数中使用工作区中更改名称的变量

Use variables with changing names from workspace in MatLab function

所以我使用了一个名为 cpselect(图像处理工具箱)的函数,它基本上是 returns 图像中我想要的点的像素值 (x,y)。然后将像素值作为变量保存在工作区中。 所以我有两个问题:

1) 我需要在函数中使用这些变量。我有几张图片,在使用 cpselect 之后,我在工作区中获得了 fixedPoints、fixedPoints1、fixedPoints2 等。



function [] = ControlPoints()
%function that reads images in directory and uses cpselect to each 
    imagefiles = dir('*.jpg');      
    nfiles = length(imagefiles); 
    for ii=1:nfiles
       currentfilename = imagefiles(ii).name;
       currentimage = imread(currentfilename);
       cpselect(currentimage,currentimage); 
       pause; 
     end
     a = fixedPoints1;  % returns error(undefined variable)   
end

有没有办法在同一个函数中使用这些变量?它们是在工作区中创建的,而不是在函数本身中创建的,这就是我在尝试使用它时遇到错误的原因。

2)找到使用方法后,出现第二个问题。我得到的变量是 fixedPoints、fixedPoints1、fixedPoints2 等……我想将它们全部放在一个元胞数组中,以便在同一个函数或另一个函数中使用。我到底该怎么做?我知道动态创建这样的变量名是不好的,但鉴于这种情况,我认为我别无选择。

提前致谢

这两个问题都可以使用 the documentation 中显示的最后一个语法来解决:

[selectedMovingPoints,selectedFixedPoints] = cpselect(currentimage,currentimage,'Wait',true)

返回的数组是 px2 数值数组,其中每一行都是所选点之一。