Got Questions? Get Answers.
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
extract every layer of a 3d matrix

Subject: extract every layer of a 3d matrix

From: Raymond

Date: 31 Oct, 2013 20:49:06

Message: 1 of 7

Hi all,
I got a 3d matrix whose dimension is 32*32*32. I want to extract every layer in Z direction using a loop. why don't my code below work? I'd very appreciate your help.

for ii=1:32
    V(:,:,ii)=['vflame' num2str(ii)];
end

Best,
Raymond

Subject: extract every layer of a 3d matrix

From: Matt Kindig

Date: 31 Oct, 2013 21:19:27

Message: 2 of 7

"Raymond " <leiqingchun@aliyun.com> wrote in message <l4ufo2$dva$1@newscl01ah.mathworks.com>...
> Hi all,
> I got a 3d matrix whose dimension is 32*32*32. I want to extract every layer in Z direction using a loop. why don't my code below work? I'd very appreciate your help.
>
> for ii=1:32
> V(:,:,ii)=['vflame' num2str(ii)];
> end
>
> Best,
> Raymond

Hi Raymond,

This is rather confusing-- if you already have the 3D matrix of size 32x32x32, then you already have every "layer" in the Z-direction, as the third-dimension of your matrix. What exactly are you trying to do?

Matt

Subject: extract every layer of a 3d matrix

From: James Tursa

Date: 31 Oct, 2013 21:29:08

Message: 3 of 7

"Raymond " <leiqingchun@aliyun.com> wrote in message <l4ufo2$dva$1@newscl01ah.mathworks.com>...
> Hi all,
> I got a 3d matrix whose dimension is 32*32*32. I want to extract every layer in Z direction using a loop. why don't my code below work? I'd very appreciate your help.
>
> for ii=1:32
> V(:,:,ii)=['vflame' num2str(ii)];
> end

Not sure what you are really trying to do here. Maybe this???

 for ii=1:32
     V(:,:,ii)=eval(['vflame' num2str(ii)]);
 end

James Tursa

Subject: extract every layer of a 3d matrix

From: Raymond

Date: 1 Nov, 2013 14:10:11

Message: 4 of 7


> Hi Raymond,
>
> This is rather confusing-- if you already have the 3D matrix of size 32x32x32, then you already have every "layer" in the Z-direction, as the third-dimension of your matrix. What exactly are you trying to do?
>
> Matt

Hi Matt,

I'm sorry about the confusing description. Yea, I got a 3D matrix V(:,:,:) of size 32x32x32. I just want to extract every layer into a 2D array. Like vflame1=V(:,:,1), vflame2=V(:,:,2),...vflame32=V(:,:,32). I just want to do it using a loop.

Raymond

Subject: extract every layer of a 3d matrix

From: Raymond

Date: 1 Nov, 2013 14:15:12

Message: 5 of 7

 
> Not sure what you are really trying to do here. Maybe this???
>
> for ii=1:32
> V(:,:,ii)=eval(['vflame' num2str(ii)]);
> end
>
> James Tursa

Hi James,

Thanks for your reply. Yea, this is exactly what I want to do. But, Why don't your code work either?
When I do:
for ii=1:32
      V(:,:,ii)=eval(['vflame' num2str(ii)]);
  end
An error 'Error using eval
Undefined function or variable 'vflame1'.' appeared.

Raymond

Subject: extract every layer of a 3d matrix

From: Bruce Bowler

Date: 1 Nov, 2013 14:51:00

Message: 6 of 7

On Fri, 01 Nov 2013 14:15:12 +0000, Raymond wrote:

>> Not sure what you are really trying to do here. Maybe this???
>>
>> for ii=1:32
>> V(:,:,ii)=eval(['vflame' num2str(ii)]);
>> end
>>
>> James Tursa
>
> Hi James,
>
> Thanks for your reply. Yea, this is exactly what I want to do. But, Why
> don't your code work either?
> When I do:
> for ii=1:32
> V(:,:,ii)=eval(['vflame' num2str(ii)]);
> end
> An error 'Error using eval Undefined function or variable 'vflame1'.'
> appeared.
>
> Raymond

Maybe I'm missing something but why are you 'inserting' if you want
'extract'?

I would think something more like (completely untested)

for ii = 1:32
    eval(['vflame' num2str(ii) '=V(:,:,' num2str(ii) ');']);
end

would be what you want.

Subject: extract every layer of a 3d matrix

From: Steven Lord

Date: 4 Nov, 2013 15:53:26

Message: 7 of 7


"Raymond " <leiqingchun@aliyun.com> wrote in message
news:l50co3$11r$1@newscl01ah.mathworks.com...
>
>> Hi Raymond,
>>
>> This is rather confusing-- if you already have the 3D matrix of size
>> 32x32x32, then you already have every "layer" in the Z-direction, as the
>> third-dimension of your matrix. What exactly are you trying to do?
>>
>> Matt
>
> Hi Matt,
>
> I'm sorry about the confusing description. Yea, I got a 3D matrix V(:,:,:)
> of size 32x32x32. I just want to extract every layer into a 2D array. Like
> vflame1=V(:,:,1), vflame2=V(:,:,2),...vflame32=V(:,:,32). I just want to
> do it using a loop.

DON'T DO THIS.

See question 1 in the Programming section of the FAQ for why this is a Bad
Idea.

http://matlab.wikia.com/wiki/FAQ

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us