Re: Create empty 3-by-3 matrix




"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


.



Relevant Pages

  • Re: Gaussian cluster antenna array data
    ... A gaussian array is aimed towards resonant elements in cluster form. ... but these dimensions have not been ...
    (rec.radio.amateur.antenna)
  • Re: How to copy non-contiguous columns to a text file
    ... a single output string could theoretically exceed the limits of the String data type. ... Unlikely as all that might seem, I refer to design algorithms that do not break when expected limits are exceeded. ... I vaguely remember that some other applications requires the empty line at the end when they import the file. ... The last line, then, should be the Record.Count since the first record is elementof the array. ...
    (microsoft.public.excel)
  • RE: Mass Adding Comments
    ... insert code to fill your own array as desired at the beginning of the ... 'Determine number of dimensions in array using Chip Pearson's method ... ' Loop, increasing the dimension index Ndx, until an error occurs. ... 'Exit sub if dimensions do not match ...
    (microsoft.public.excel.programming)
  • Re: Gaussian cluster antenna array data
    ... A gaussian array is aimed towards resonant elements in cluster form. ... but these dimensions have not been ...
    (rec.radio.amateur.antenna)
  • RE: Mass Adding Comments
    ... insert code to fill your own array as desired at the beginning of the ... 'Determine number of dimensions in array using Chip Pearson's method ... ' Loop, increasing the dimension index Ndx, until an error occurs. ... 'Exit sub if dimensions do not match ...
    (microsoft.public.excel.programming)