Borrar filtros
Borrar filtros

Saving variable names into an cell array for later use in a for/while-loop.

1 visualización (últimos 30 días)
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.

Respuestas (1)

dpb
dpb el 22 de Abr. de 2014
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 comentarios
Norianne Ingram
Norianne Ingram el 21 de Mayo de 2016
Yeah, well, if it is possible we WANT to know how to do it. I've read that FAQ page 30x.
Walter Roberson
Walter Roberson el 21 de Mayo de 2016
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"

Iniciar sesión para comentar.

Categorías

Más información sobre Convert Image Type en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by