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:
cell syntax, iteration

Subject: cell syntax, iteration

From: Raymond

Date: 1 Oct, 2010 20:39:04

Message: 1 of 3

I'm writing a function that takes the first letter of the first subcell, takes the whole second subcell, and takes the corresponding element of the third vector and concatanates them into a output. Examples to help in understanding:

in = {{'Ksda','Jasdas','Ias'},{'Swe','Mao','Ori'}, [9 4 2]}
out= {'kswe9','jmao4','iori2'}

in={{'Dasdasd', 'Eras', 'Ias', 'Sdas'}, {'Wsse', 'Tws', 'Dss', 'Sasd'}, [1 2 3 4]}
out={'dwsse1', 'etws2', 'idss3', 'ssasd4'}

The inputs will always be in this form of three subcells. Two cells and one vector.
Notice that the output will always be lower case.



My function so far:

function [out] = multicombine(in )

a = [];
b = [];
c = [];
for i=1:length(cell{1})
    a1 = lower(cell{1}(i));
    a(i) = a1{1}(1);
    a = char(a);
    g=lower(cell{2}(i));
    b=[b char(g{1})];
    c(i)=cell{3}(i);
out(i)=strcat(a(i), b(i), c(i));
end

end

I think it should work, yet it doesn't. Can't figure it out for the life of me.

Subject: cell syntax, iteration

From: Sean

Date: 1 Oct, 2010 21:02:19

Message: 2 of 3

"Raymond " <atlantaswagsurfers3@yahoo.com> wrote in message <i85gt8$31r$1@fred.mathworks.com>...
> I'm writing a function that takes the first letter of the first subcell, takes the whole second subcell, and takes the corresponding element of the third vector and concatanates them into a output. Examples to help in understanding:
>
> in = {{'Ksda','Jasdas','Ias'},{'Swe','Mao','Ori'}, [9 4 2]}
> out= {'kswe9','jmao4','iori2'}
>
> in={{'Dasdasd', 'Eras', 'Ias', 'Sdas'}, {'Wsse', 'Tws', 'Dss', 'Sasd'}, [1 2 3 4]}
> out={'dwsse1', 'etws2', 'idss3', 'ssasd4'}
>
> The inputs will always be in this form of three subcells. Two cells and one vector.
> Notice that the output will always be lower case.
>
>
>
> My function so far:
>
> function [out] = multicombine(in )
>
> a = [];
> b = [];
> c = [];
> for i=1:length(cell{1})
> a1 = lower(cell{1}(i));
> a(i) = a1{1}(1);
> a = char(a);
> g=lower(cell{2}(i));
> b=[b char(g{1})];
> c(i)=cell{3}(i);
> out(i)=strcat(a(i), b(i), c(i));
> end
>
> end
>
> I think it should work, yet it doesn't. Can't figure it out for the life of me.


This should be all you need:
%%
out = cell(1,length(in{1}));
for ii=1:length(in{1})
    a = char(in{1}(ii));
    b = char(in{2}(ii));
    c = num2str(in{3}(ii));
    out{ii}=lower([a(1), b, c]);
end

%SCd

Subject: cell syntax, iteration

From: Raymond

Date: 1 Oct, 2010 22:30:11

Message: 3 of 3

Sean, thank you VERY much.
"Sean " <sean.dewolski@nospamplease.umit.maine.edu> wrote in message <i85i8r$2r2$1@fred.mathworks.com>...
> "Raymond " <atlantaswagsurfers3@yahoo.com> wrote in message <i85gt8$31r$1@fred.mathworks.com>...
> > I'm writing a function that takes the first letter of the first subcell, takes the whole second subcell, and takes the corresponding element of the third vector and concatanates them into a output. Examples to help in understanding:
> >
> > in = {{'Ksda','Jasdas','Ias'},{'Swe','Mao','Ori'}, [9 4 2]}
> > out= {'kswe9','jmao4','iori2'}
> >
> > in={{'Dasdasd', 'Eras', 'Ias', 'Sdas'}, {'Wsse', 'Tws', 'Dss', 'Sasd'}, [1 2 3 4]}
> > out={'dwsse1', 'etws2', 'idss3', 'ssasd4'}
> >
> > The inputs will always be in this form of three subcells. Two cells and one vector.
> > Notice that the output will always be lower case.
> >
> >
> >
> > My function so far:
> >
> > function [out] = multicombine(in )
> >
> > a = [];
> > b = [];
> > c = [];
> > for i=1:length(cell{1})
> > a1 = lower(cell{1}(i));
> > a(i) = a1{1}(1);
> > a = char(a);
> > g=lower(cell{2}(i));
> > b=[b char(g{1})];
> > c(i)=cell{3}(i);
> > out(i)=strcat(a(i), b(i), c(i));
> > end
> >
> > end
> >
> > I think it should work, yet it doesn't. Can't figure it out for the life of me.
>
>
> This should be all you need:
> %%
> out = cell(1,length(in{1}));
> for ii=1:length(in{1})
> a = char(in{1}(ii));
> b = char(in{2}(ii));
> c = num2str(in{3}(ii));
> out{ii}=lower([a(1), b, c]);
> end
>
> %SCd

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