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:
want to save file using variable name

Subject: want to save file using variable name

From: Moon Datta

Date: 27 Sep, 2012 11:36:07

Message: 1 of 4

I have a programme like

index_1 = find(p==1,1440);
index_2 = find(p==2,1440);
index_3 = find(p==3,1440);
index_4 = find(p==4,1440);
index_5 = find(p==5,1440);

where p is a matrix.
I want to make it in one line. any hint please.....

thanks in advance.

Subject: want to save file using variable name

From: Sadik

Date: 27 Sep, 2012 12:43:08

Message: 2 of 4

Hi Moon,

First attempt:

for k = 1:5
    eval(['index_' num2str(k) ' = find(p==' num2str(k) ',1440);']);
end

Best.

Subject: want to save file using variable name

From: dpb

Date: 27 Sep, 2012 12:55:30

Message: 3 of 4

On 9/27/2012 6:36 AM, Moon Datta wrote:
> I have a programme like
>
> index_1 = find(p==1,1440);
> index_2 = find(p==2,1440);
> index_3 = find(p==3,1440);
> index_4 = find(p==4,1440);
> index_5 = find(p==5,1440);
>
> where p is a matrix. I want to make it in one line. any hint please.....

Don't do that--use an array instead...then probably just as well to use
a loop as anything else't--

for i=1:5,idx(i)=find(p==i,1440);end

--

Subject: want to save file using variable name

From: Steven_Lord

Date: 27 Sep, 2012 13:58:01

Message: 4 of 4



"Moon Datta" <monti.tata2012@gmail.com> wrote in message
news:k41dn7$ikr$1@newscl01ah.mathworks.com...
> I have a programme like
>
> index_1 = find(p==1,1440);
> index_2 = find(p==2,1440);
> index_3 = find(p==3,1440);
> index_4 = find(p==4,1440);
> index_5 = find(p==5,1440);
>
> where p is a matrix. I want to make it in one line. any hint please.....

No, you do NOT want to do that at all. See question 6 in the Programming
section of the FAQ for some of the reasons why and alternatives you should
use instead.

http://matlab.wikia.com/wiki/FAQ

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

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