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:
find/logical indexing and mat2str

Subject: find/logical indexing and mat2str

From: Rich

Date: 16 Oct, 2009 14:09:03

Message: 1 of 1

Hi,

I was wondering if someone could point me in the direction of what function to use in order to collapse a logical array into a 1-dimensional vector of strings containing the logical indices.
This is the clunky way I'm currently doing it:

i.e.
A = [1,1,0;0,0,1]
A =
     1 1 0
     0 0 1

[a,b]=find(A);

for i=1:size(A,1)
    strindx(i,1)={mat2str(b(a==i))}
end

strindx =

    '[1;2]'
    '3'

Obviously I want to get rid of the loop for large A's
My thoughts would be to somehow generate a matrix B from A to look something like :
B = [1,2,0;3,0,0]

B =

     1 2 0
     3 0 0

Then somehow strip the zeros, and collapse columns into a 1-dimensional vector!
Any ideas?

Thanks for the tips...
(PS- end purpose of this is just record keeping, i.e. keeping track of the logical array, A is generally highly sparse, and the rows have specific individual meanings, hence the desire to collapse to 1D column vector - plus for convenience of reading, it gets dumped into excel..) So if there is another way...

thanks!
Richard

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