I have variable name ROI_Mask_1, ......, ROI_Mask_9
and while using for loop like this,
for roi= 1:9
Ref_L2(dates).SREF(bands).Sur_Ref_L2_MASK(roi,1) = mean(Sur_Ref_L2(mask_real_data & ROI_Mask_,(num2str(roi))));
end
I am getting error;
Unrecognized function or variable 'ROI_Mask'.

 採用された回答

David Hill
David Hill 2022 年 3 月 17 日

0 投票

If you can advoid it, you should never make multiple variables but should place them all in a matrix. If ROI_Mask's are matrices you should just make a 3D matrix that you can index into.
ROI_Mask(:,:,1)=ROI_Mask_1;
ROI_Mask(:,:,2)=ROI_Mask_2;%repeat for all 9 (or change your code to produce them like this)
%then it is very easy to index into them
for k=1:9
Ref_L2(dates).SREF(bands).Sur_Ref_L2_MASK(k,1) = ...
mean(Sur_Ref_L2(mask_real_data & ROI_Mask(:,:,k)));
end
If ROI_Mask's are vectors, then a 2D matrix will work
ROI_Mask(1,:)=ROI_Mask_1;
ROI_Mask(2,:)=ROI_Mask_2;
for k=1:9
Ref_L2(dates).SREF(bands).Sur_Ref_L2_MASK(k,1) = ...
mean(Sur_Ref_L2(mask_real_data & ROI_Mask(k,:)));
end

3 件のコメント

Rahul Shah
Rahul Shah 2022 年 3 月 17 日
my ROI_Mask_1 ....9 each ROI_Mask contains 7081x7801 size of logical matrix.
David Hill
David Hill 2022 年 3 月 17 日
Then the top code section above should work for you, just convert all your ROI_Mask's into a single 3D matrix.
Rahul Shah
Rahul Shah 2022 年 3 月 17 日
Thank you David, its working now.

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

その他の回答 (0 件)

製品

リリース

R2020b

質問済み:

2022 年 3 月 17 日

コメント済み:

2022 年 3 月 17 日

Community Treasure Hunt

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

Start Hunting!

Translated by