在MATLAB中的循环内动态更改变量名 [英] Dynamically change variable name inside a loop in MATLAB
问题描述
此脚本用于图像处理,方法是将2000个图像集与一个蒙版相乘,然后对每个帧中的值求和.这些值输入到称为强度的行向量中.
This script is being used for image processing by multiplying a set of 2000 images with a mask and then summing the values in each frame. These values are entered into a row vector called Intensity.
我试图以20个行向量结束,称为强度1,intesity2 ... intensity20,是否有一种简单的方法可以在每次循环迭代时更改强度行向量的名称?
I am trying to end up with 20 row vectors called intensity1, intesity2...intensity20, is there a straight forward way to change the name of the Intensity row vector upon every loop iteration?
for m=1:20
mask=bigrating(m,m,0);
for n=1:2000
I=sum(sum(imread((sprintf('image%05d.tif',n))).*(mask)));
Intensity(n)=I;
end
save('filepath','Intensity')
end
推荐答案
由于您希望动态命名强度1,强度2,.... intensity20等,因此以下内容对您来说很有效:
Because you wanted dynamically named intensity1, intensity2,....intensity20 etc, the following should work for you:
for m = 1:20
mask = bigrating(m,m,0)
for n = 1:2000
I=sum(sum(imread((sprintf('image%05d.tif',n))).*(mask)));
eval(['intensity' num2str(m) ' = I'])
end
save('filepath', ['intensity' num2str(m)])
end
这篇关于在MATLAB中的循环内动态更改变量名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!