Re: Create empty 3-by-3 matrix
- From: "Steven Lord" <slord@xxxxxxxxxxxxx>
- Date: Thu, 23 Jul 2009 09:18:34 -0400
"Christine " <christine_gee@xxxxxxxxxxx> wrote in message
news:h49mmu$c4d$1@xxxxxxxxxxxxxxxxxxxxx
Hi,
I know that to create a 0-by-0 matrix, we can use the square bracket
operators with no value specified:
A = [];
but, what abt when we want to create an empty 3-by-3 matrix?
That's a contradiction in terms. In MATLAB, an empty matrix (as defined by
the ISEMPTY function) is one whose size in at least one dimension is 0. A
3-by-3 matrix does not have size 0 in any of its dimensions, and so is not
empty.
If you want to create a 3-by-3 matrix of zeros (which is what I'd usually
think of when I hear the phrase "empty 3-by-3 matrix") then use the ZEROS
function as you did below. If you want an empty array whose size in the
first two dimensions is [3 3] then use:
A = zeros(3, 3, 0);
Note that this is not a matrix but an N-D array, and so things like matrix
multiplication that are only defined for matrices will not work.
If instead you want a 3-by-3 array each element of which is a 0-by-0 empty
matrix, you will need to use a cell array.
A = repmat({[]}, 3, 3);
Again, this is an array not a matrix, and so you can't use it for matrix
multiplication or the like.
my solution will be
A = zeros(3,3)
for i=1:3
for j=1:3
A(i,j)=[];
end
end
This will not work; after the first deletion, A will be reshaped to an
8-by-1 vector, and so the second deletion [where you try to delete A(1, 2)]
will fail because A no longer has a second column. Even if you tried doing
this with linear indexing:
A = zeros(3, 3);
for k = 1:9
A(k) = [];
end
it would fail with k = 6, as by that point A would only have 4 elements
left.
--
Steve Lord
slord@xxxxxxxxxxxxx
.
- References:
- Create empty 3-by-3 matrix
- From: Christine
- Create empty 3-by-3 matrix
- Prev by Date: Re: Zadoff-Chu sequences in LTE
- Next by Date: Is it possible to wrap a picture around a mesh?
- Previous by thread: Re: Create empty 3-by-3 matrix
- Next by thread: Is it possible to wrap a picture around a mesh?
- Index(es):
Relevant Pages
|