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"
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!