Saving variable names into an cell array for later use in a for/while-loop.
2 次查看(过去 30 天)
显示 更早的评论
Hello!
This might be a stupid question, but i cant find a solution for it either here on anywhere on google so i thought i might just try you guys!
I recently started playing a big with images and such, just to practice it. What i want to do is get sixteen diffrent images merged together. I managed to do that just fine, the problem occurred when i tried to make an image that were changing the order of those sixteen images, sort of a GIF.
What i tried to do was to save the diffrent images in a cell array:
Cell={'img1', 'img2', 'img3', ... , 'img16'}
Then, depending on which value a certain variable had, i'd assign a new cell array the correct image for that value:
for j=1:12
if rem(nthroot(value,j),1)==0
img{i}=cell{j};
elseif value==3
img{i}='img3'
end
end
when i later wanted to use is in the image i had it go like this:
collImg = [imresize(img{1},newSize),imresize(img{2},newSize);imresize(img{3},newSize), ... , imresize(img{16},newSize)]
The problem is: The "imresize" wont accept any of the variables i try to extract from the cell array, i've tried with both common parantesis and with the specific for cell arrays. Is it possible to do it like this, or am i working on something impossible?
I'm sorry if this is messy.
0 个评论
回答(1 个)
dpb
2014-4-22
It's possible, but don't do that! ... To see why and ways to do the same thing w/o 'poofing' variables into the workspace, see
2 个评论
Norianne Ingram
2016-5-21
Yeah, well, if it is possible we WANT to know how to do it. I've read that FAQ page 30x.
Walter Roberson
2016-5-21
But you missed the part that starts,
"Now, if you still really want to go against our advice and create variables with dynamically generated names"
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Convert Image Type 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!