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

问题描述 投票:0回答:1

所以我使用的是一个名为cpselect(图像处理工具箱)的函数,它基本上返回了图像中我想要的点的像素值(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等...我想将它们全部放在一个单元格数组中,以便在同一个函数或另一个函数中使用。我怎么能这样做?我觉得动态创建这样的变量名称是不好的但是考虑到我不认为我有选择的情况。

提前致谢

matlab function variables workspace
1个回答
0
投票

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

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

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

© www.soinside.com 2019 - 2024. All rights reserved.