[英]Use variables with changing names from workspace in MatLab function
所以我使用的是一個名為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等...我想將它們全部放在一個單元格數組中,以便在同一個函數或另一個函數中使用。 我怎么能這樣做? 我覺得動態創建這樣的變量名稱是不好的但是考慮到我不認為我有選擇的情況。
提前致謝
使用文檔中顯示的最后一個語法可以解決這兩個問題:
[selectedMovingPoints,selectedFixedPoints] = cpselect(currentimage,currentimage,'Wait',true)
返回的數組是p
x2數值數組,其中每行是所選的點之一。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.