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:
How to delete a row from a 3D array DIRECTLY?

Subject: How to delete a row from a 3D array DIRECTLY?

From: chris wang

Date: 14 Apr, 2010 06:23:05

Message: 1 of 5

I have a 3D array Sigma as follows, I want to delete the first row, but
Sigma(1,:,)=[] doesn't work, the error message is
??? A null assignment can have only one non-colon index.

I hate to let Sigma(:,:,1) be some 2d matrix and perform the deletion in 2d, is there anyway to do the deletion in 3D? Thank you very much!

****************************************************
Sigma(:,:,1) =

    3.1793 5.7411 7.7806 7.7806 7.7806 7.7806
    2.0904 5.2809 2.8295 2.8295 2.8295 2.8295
    0.6918 5.8785 3.6237 3.6237 3.6237 3.6237
    1.0858 1.5140 6.1877 6.1877 6.1877 6.1877
    3.5030 4.4238 6.4445 6.4445 6.4445 6.4445
    0.5461 0.0705 15.6467 15.6467 15.6467 15.6467
    3.5756 1.1948 14.5027 14.5027 14.5027 14.5027
    1.1949 3.9687 0.0390 0.0390 0.0390 0.0390


Sigma(:,:,2) =

    5.1376 2.8153 18.5234 18.5234 18.5234 18.5234
    4.2591 5.9300 14.3468 14.3468 14.3468 14.3468
    6.3312 2.5410 30.5501 30.5501 30.5501 30.5501
    6.0620 2.0037 29.6095 29.6095 29.6095 29.6095
    5.7316 1.3557 29.3806 29.3806 29.3806 29.3806
    6.3192 4.5622 28.6102 28.6102 28.6102 28.6102
    6.1193 3.8432 26.2318 26.2318 26.2318 26.2318
    4.8363 2.2789 17.6792 17.6792 17.6792 17.6792

Subject: How to delete a row from a 3D array DIRECTLY?

From: norbert kirchgessner

Date: 14 Apr, 2010 06:49:03

Message: 2 of 5

"chris wang" <wangweichris@gmail.com> wrote in message <hq3n09$o7b$1@fred.mathworks.com>...
> I have a 3D array Sigma as follows, I want to delete the first row, but
> Sigma(1,:,)=[] doesn't work, the error message is
> ??? A null assignment can have only one non-colon index.
>
> I hate to let Sigma(:,:,1) be some 2d matrix and perform the deletion in 2d, is there anyway to do the deletion in 3D? Thank you very much!
>
> ****************************************************
> Sigma(:,:,1) =
>
> 3.1793 5.7411 7.7806 7.7806 7.7806 7.7806
> 2.0904 5.2809 2.8295 2.8295 2.8295 2.8295
> 0.6918 5.8785 3.6237 3.6237 3.6237 3.6237
> 1.0858 1.5140 6.1877 6.1877 6.1877 6.1877
> 3.5030 4.4238 6.4445 6.4445 6.4445 6.4445
> 0.5461 0.0705 15.6467 15.6467 15.6467 15.6467
> 3.5756 1.1948 14.5027 14.5027 14.5027 14.5027
> 1.1949 3.9687 0.0390 0.0390 0.0390 0.0390
>
>
> Sigma(:,:,2) =
>
> 5.1376 2.8153 18.5234 18.5234 18.5234 18.5234
> 4.2591 5.9300 14.3468 14.3468 14.3468 14.3468
> 6.3312 2.5410 30.5501 30.5501 30.5501 30.5501
> 6.0620 2.0037 29.6095 29.6095 29.6095 29.6095
> 5.7316 1.3557 29.3806 29.3806 29.3806 29.3806
> 6.3192 4.5622 28.6102 28.6102 28.6102 28.6102
> 6.1193 3.8432 26.2318 26.2318 26.2318 26.2318
> 4.8363 2.2789 17.6792 17.6792 17.6792 17.6792

Hi,

you made a typo, try

Sigma(1,:,:) = [];

hth
kinor

Subject: How to delete a row from a 3D array DIRECTLY?

From: chris wang

Date: 14 Apr, 2010 07:35:04

Message: 3 of 5

thanks, I copied the wrong command, the issue is still that you cannot delete with two out of three indices present.

>> Sigma(1,:,2) = [];
??? A null assignment can have only one non-colon index.



"Norbert Kirchgessner" <kinor@gmx.de> wrote in message <hq3ogv$eac$1@fred.mathworks.com>...
> "chris wang" <wangweichris@gmail.com> wrote in message <hq3n09$o7b$1@fred.mathworks.com>...
> > I have a 3D array Sigma as follows, I want to delete the first row, but
> > Sigma(1,:,)=[] doesn't work, the error message is
> > ??? A null assignment can have only one non-colon index.
> >
> > I hate to let Sigma(:,:,1) be some 2d matrix and perform the deletion in 2d, is there anyway to do the deletion in 3D? Thank you very much!
> >
> > ****************************************************
> > Sigma(:,:,1) =
> >
> > 3.1793 5.7411 7.7806 7.7806 7.7806 7.7806
> > 2.0904 5.2809 2.8295 2.8295 2.8295 2.8295
> > 0.6918 5.8785 3.6237 3.6237 3.6237 3.6237
> > 1.0858 1.5140 6.1877 6.1877 6.1877 6.1877
> > 3.5030 4.4238 6.4445 6.4445 6.4445 6.4445
> > 0.5461 0.0705 15.6467 15.6467 15.6467 15.6467
> > 3.5756 1.1948 14.5027 14.5027 14.5027 14.5027
> > 1.1949 3.9687 0.0390 0.0390 0.0390 0.0390
> >
> >
> > Sigma(:,:,2) =
> >
> > 5.1376 2.8153 18.5234 18.5234 18.5234 18.5234
> > 4.2591 5.9300 14.3468 14.3468 14.3468 14.3468
> > 6.3312 2.5410 30.5501 30.5501 30.5501 30.5501
> > 6.0620 2.0037 29.6095 29.6095 29.6095 29.6095
> > 5.7316 1.3557 29.3806 29.3806 29.3806 29.3806
> > 6.3192 4.5622 28.6102 28.6102 28.6102 28.6102
> > 6.1193 3.8432 26.2318 26.2318 26.2318 26.2318
> > 4.8363 2.2789 17.6792 17.6792 17.6792 17.6792
>
> Hi,
>
> you made a typo, try
>
> Sigma(1,:,:) = [];
>
> hth
> kinor

Subject: How to delete a row from a 3D array DIRECTLY?

From: us

Date: 14 Apr, 2010 08:09:39

Message: 4 of 5

"chris wang" <wangweichris@gmail.com> wrote in message <hq3r78$mke$1@fred.mathworks.com>...
> thanks, I copied the wrong command, the issue is still that you cannot delete with two out of three indices present.
>
> >> Sigma(1,:,2) = [];
> ??? A null assignment can have only one non-colon index.

well... fortunately(!) ML is doing the right thing...
just think...

     m=repmat(magic(2),[1,1,3]);
% now
     m(1,:,2)=nan
%{
% m =
m(:,:,1) =
     1 3
     4 2
m(:,:,2) =
   NaN NaN % <- this is what you want to replace with [], ie, remove...
     4 2
m(:,:,3) =
     1 3
     4 2
%}
% how can this possibly work...

us

Subject: How to delete a row from a 3D array DIRECTLY?

From: Steven Lord

Date: 14 Apr, 2010 14:11:02

Message: 5 of 5


"chris wang" <wangweichris@gmail.com> wrote in message
news:hq3r78$mke$1@fred.mathworks.com...
> thanks, I copied the wrong command, the issue is still that you cannot
> delete with two out of three indices present.
>
>>> Sigma(1,:,2) = [];
> ??? A null assignment can have only one non-colon index.

That's correct. If that command worked, the first page would have one more
row than the second. That would make the array non-rectangular, and that's
not allowed in MATLAB.

Either delete the first row across ALL the pages or set the values you'd
like to "delete" to some value that clearly indicates they should no longer
be used in your calculations -- NaN is a popular choice for that
"placeholder" role.

--
Steve Lord
slord@mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ

Tags for 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