Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: convert string to scalar, Is it possible?
Replies: 5   Last Post: Feb 6, 2013 3:57 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Derek Goring

Posts: 3,919
Registered: 12/7/04
Re: convert string to scalar, Is it possible?
Posted: Feb 6, 2013 3:57 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

On Wednesday, February 6, 2013 9:40:07 PM UTC+13, grega wrote:
> Thank you for you kind suggestion, but the problem is that the indices and variables are provided in mentioned forms and are of size > 300. If I do this by hand each time I get new set of indices and variables, I'll go crzy...
>
>
>
>
>
> TideMan <mulgor@gmail.com> wrote in message <7eb0e508-ac40-4df2-ad77-a77d71da185d@googlegroups.com>...
>

> > On Wednesday, February 6, 2013 9:18:08 PM UTC+13, grega wrote:
>
> > > I have number of column indeces, e.g. A = [1, 4, 6,...] and corresponding labels in strings, e.g. B = {'a' 'b' 'c' ...}, so I would like to assign indeces to corresponding strings, so that the results is:
>
> > >
>
> > > a = 1;
>
> > >
>
> > > b = 4;
>
> > >
>
> > > c = 6;
>
> > >
>
> > > ...
>
> > >
>
> > >
>
> > >
>
> > > Hope I provided a bit more insight for suggestions :) Tnx
>
> > >
>
> > >
>
> > >
>
> > > >
>
> > >
>
> > > > yes it is possible, but first of all, really think about why you want to do this?
>
> > >
>
> > > >
>
> > >
>
> > > > help eval
>
> > >
>
> > > >
>
> > >
>
> > > > ~ Jos
>
> >
>
> > DON'T DO THIS!!
>
> >
>
> > You will end up in an awful muddle and no one here will have any sympathy for you.
>
> > Instead, learn to use structures, whence you would have:
>
> > s.a=1
>
> > s.b=4
>
> > s.c=6
>
> > Believe me, learning this will improve the quality of your life.

Who is suggesting you do it manually?
That's the very reason for using structures: so that you can do whatever you want to do automatically.
help setfield
will get you started.

Another way is:
for ix=1:length(string)
s.(string{ix})=x(ix);
end
where string is a cell array containing your variable names and x is a numerical array containing your data.




Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.