Change name of variable at each iteration of a for loop

I am using Matlab to do image processing on 3D image stacks. I am importing several image stacks at the same time, then doing work on them. I want to call the first image stack "bkg0" and the second "bkg1" etc. until I have imported all of the images. The number of images, however is variable depending on the data set that I've collected. Is it possible to do this?
The idea I want is something like this:
for i=1:size(ls,1);
bkg'num2str(i)'= load image;
end;
where each image is a 3d image stack, and the 'num2str(i)' section goes from 1 to the size of the listed data (ls).
Any ideas?
Kolbein

 採用された回答

Image Analyst
Image Analyst 2012 年 1 月 17 日

1 投票

You can read them all into cells of a cell array. The name of the cell array stays the same, you just use a different index (the loop index) to stuff the image into different cells in the cell array. Something like:
for k = 1 : size(ls,1);
bkg{k} = imread(fullFileName);
end

その他の回答 (2 件)

aditya
aditya 2012 年 1 月 16 日

0 投票

hi kolbein, you should check out this http://www.mathworks.com/matlabcentral/fileexchange/4871

1 件のコメント

Walter Roberson
Walter Roberson 2012 年 1 月 16 日
I don't see how that will do anything useful at all for Kolbein ??

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

カテゴリ

ヘルプ センター および File ExchangeLoops and Conditional Statements についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by