Skip to Main Content Skip to Search
Login
File Exchange
MATLAB Newsgroup
Link Exchange
  Blogs  
 Contest 
MathWorks.com

Thread Subject: 3D matrix

Subject: 3D matrix

From: mark b.

Date: 16 May, 2008 10:12:02

Message: 1 of 9

hi,
i've got three vectors: a,b,c. each of it with length=97.
i need to do a 3d matrix, in which i'll have a,b,c..
i'm sure that is very simple, but i've found some
difficulties:/

Subject: Re: 3D matrix

From: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)

Date: 16 May, 2008 18:11:03

Message: 2 of 9

In article <g0jmli$ah$1@fred.mathworks.com>,
mark b. <john.doe.nospam@mathworks.com> wrote:

>i've got three vectors: a,b,c. each of it with length=97.
>i need to do a 3d matrix, in which i'll have a,b,c..
>i'm sure that is very simple, but i've found some
>difficulties:/

Please explain more clearly what the 3D matrix output should
look like. Based upon what you said, it looks to me to be
more likely that you want the 2D matrix

output = [a(:);b(:);c(:)]


If not then my next best guess would be that you want

[ta tb tc] = ndgrid(a,b,c);
output = cat(3,ta,tb,tc);

--
  "We worked every day, Sunday included, until at least ten
  o'clock at night. I remember it was an event when we quit work
  on Christmas night at eight o'clock to attend a family reunion."
                            -- Walter Davidson (of Harley-Davidson)

Subject: Re: 3D matrix

From: mark b.

Date: 17 May, 2008 08:02:02

Message: 3 of 9

[ta tb tc] = ndgrid(a,b,c);
output = cat(3,ta,tb,tc);

that is exacly what i want! thank You very much:)

Subject: Re: 3D matrix

From: mark b.

Date: 17 May, 2008 08:14:01

Message: 4 of 9

sorry, i took a look once again and it's not exacly what i
wanted.
consider:

a=1:5;
b=2:6;
c=3:7;
[ta tb tc] = ndgrid(a,b,c);
output = cat(3,ta,tb,tc);

then size(output) will be 5x5x15
and i need the matrix to be 5x5x5 (axbxc)

Subject: Re: 3D matrix

From: John D'Errico

Date: 17 May, 2008 09:08:03

Message: 5 of 9

"mark b." <john.doe.nospam@mathworks.com> wrote in message
<g0m449$nsj$1@fred.mathworks.com>...
> sorry, i took a look once again and it's not exacly what i
> wanted.
> consider:
>
> a=1:5;
> b=2:6;
> c=3:7;
> [ta tb tc] = ndgrid(a,b,c);
> output = cat(3,ta,tb,tc);
>
> then size(output) will be 5x5x15
> and i need the matrix to be 5x5x5 (axbxc)

What matrix? What do you want this matrix
to hold? You have never yet told us this
information, just the size of it.

zeros(97,97,97)

will give you an array of the originally
requested size.

John

Subject: Re: 3D matrix

From: mark b.

Date: 17 May, 2008 09:27:02

Message: 6 of 9

i know i can make make matrix = zeros(97,97,97) and then
i'll have 3d matrix size 97x97x97.
but then i want to put inside of it a,b,c, where each is
the size of 97. so then i'll still have matrix with size
97x97x97 but with a,b and c inside..

Subject: Re: 3D matrix

From: John D'Errico

Date: 17 May, 2008 11:45:04

Message: 7 of 9

"mark b." <john.doe.nospam@mathworks.com> wrote in message
<g0m8d6$so0$1@fred.mathworks.com>...
> i know i can make make matrix = zeros(97,97,97) and then
> i'll have 3d matrix size 97x97x97.
> but then i want to put inside of it a,b,c, where each is
> the size of 97. so then i'll still have matrix with size
> 97x97x97 but with a,b and c inside..

(John takes a quiet moment to pound his
head against a brick wall. While this does
not directly relieve the pain he feels in his
head, it distracts him. It seems better now.)

But you still have not said what is in this
matrix.

A simple array in Matlab is composed of
scalar elements, each of which is a SINGLE
number or character. Those elements may
be the standard double precision numbers,
or they may be singles, uint8s, etc.

So it makes no sense that you want to put
a, b, and c inside this array. There are other
classes of variables in Matlab, such as cell
arrays or structures. And there are higher
dimensional arrays. Do you perhaps wish to
create a 4 dimensional array?

So again, what will be inside each element
of this array? Please explain yourself, as my
crystal ball is always foggy at this time of
day.

John

Subject: Re: 3D matrix

From: Peter Boettcher

Date: 17 May, 2008 14:41:43

Message: 8 of 9

"mark b." <john.doe.nospam@mathworks.com> writes:

> i know i can make make matrix = zeros(97,97,97) and then
> i'll have 3d matrix size 97x97x97.
> but then i want to put inside of it a,b,c, where each is
> the size of 97. so then i'll still have matrix with size
> 97x97x97 but with a,b and c inside..

Let's reduce this to 2D, and vectors and matrix with size 4. So I have
two 4-element vectors: [1 2 3 4] and [5 6 7 8]. I want a 4x4 matrix.
Write out the 4x4 matrix which describes where the above numbers go:

[? ? ? ?]
[? ? ? ?]
[? ? ? ?]
[? ? ? ?]

Then explain the extension to 3D.

-Peter

Subject: Re: 3D matrix

From: Skeptic

Date: 17 May, 2008 16:44:31

Message: 9 of 9

On May 17, 5:27=A0am, "mark b." <john.doe.nos...@mathworks.com> wrote:
> i know i can make make matrix =3D zeros(97,97,97) and then
> i'll have 3d matrix size 97x97x97.
> but then i want to put inside of it a,b,c, where each is
> the size of 97. so then i'll still have matrix with size
> 97x97x97 but with a,b and c inside..

------------------------------------------
mark b./john doe
So go ahead and do it. Just stick the 3 vectors in. You'll have 3
lines of numbers in a mostly empty array. Go ahead and stick them
anywhere you want - what do I care? (Others may have their own
suggestions of where you can stick them.) Sounds like you consider
this as a solution since you've stopped asking questions.
- skeptic

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

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.

rssFeed for this Thread

envelope graphic E-mail this page to a colleague

Public Submission Policy
NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Disclaimer prior to use.
Related Topics