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:
While a cell in an array isn't zeros

Subject: While a cell in an array isn't zeros

From: Mohannad

Date: 26 Jan, 2012 19:24:11

Message: 1 of 3

I'm very close to finishing this project and I just run into this one problem,
I have an array of 3 rows and m columns called system. and m gets larger at each iteration of the code.

I just need to know who can I specify in the while statement that I want the code to keep running as long as the the cell system{3,m} IS NOT all zeros? this cell is a n by 3 matrix representing forces.
Or some small value such as 1e-10 might be more appropriate.

Thank.

Subject: While a cell in an array isn't zeros

From: Abhijit Bhattacharjee

Date: 26 Jan, 2012 20:27:58

Message: 2 of 3

You may try using nnz(), which counts the number of nonzero elements in an
array.


"Mohannad " <msm36@aub.edu.lb> wrote in message
news:jfs98r$r2a$1@newscl01ah.mathworks.com...
> I'm very close to finishing this project and I just run into this one
> problem, I have an array of 3 rows and m columns called system. and m gets
> larger at each iteration of the code.
> I just need to know who can I specify in the while statement that I want
> the code to keep running as long as the the cell system{3,m} IS NOT all
> zeros? this cell is a n by 3 matrix representing forces.
> Or some small value such as 1e-10 might be more appropriate.
> Thank.

Subject: While a cell in an array isn't zeros

From: Claudio

Date: 27 Jan, 2012 16:29:09

Message: 3 of 3

Hi,

I didn't completely understand the structure of your cells, but you could try with :
while sum(system{3,5}(:) == 0) < 3*n
    % your code
end

or
while sum(system{3,5}(:) < 1e-10) < 3*n
    % your code
end

Good luck!
Claudio

"Mohannad" wrote in message <jfs98r$r2a$1@newscl01ah.mathworks.com>...
> I'm very close to finishing this project and I just run into this one problem,
> I have an array of 3 rows and m columns called system. and m gets larger at each iteration of the code.
>
> I just need to know who can I specify in the while statement that I want the code to keep running as long as the the cell system{3,m} IS NOT all zeros? this cell is a n by 3 matrix representing forces.
> Or some small value such as 1e-10 might be more appropriate.
>
> Thank.

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