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:
CAT Arguments

Subject: CAT Arguments

From: Rubi

Date: 12 Feb, 2009 23:38:01

Message: 1 of 6

I need to fix this... i got this code

V1='COMB_LIN[0,0]:=';
 for k=0:8
    for t=0:5
         cadena1=sprintf('COMB_LIN[%d,%d]:=',[k t]);
V1 =[V1 ; cadena1]; %#ok<AGROW>
    end
  end

and it works perfect ,but when i change the k=10 or more actually i need 243 it says this

??? Error using ==> vertcat
CAT arguments dimensions are not consistent.

Error in ==> ExtractOutp at 14
V1 =[V1 ; cadena1]; %#ok<AGROW>

and im not using vertcat ... thanks in advice :)

Subject: CAT Arguments

From: Roger Stafford

Date: 12 Feb, 2009 23:59:02

Message: 2 of 6

"Rubi " <phreakadelik@hotmail.com> wrote in message <gn2bsp$hfn$1@fred.mathworks.com>...
> I need to fix this... i got this code
>
> V1='COMB_LIN[0,0]:=';
> for k=0:8
> for t=0:5
> cadena1=sprintf('COMB_LIN[%d,%d]:=',[k t]);
> V1 =[V1 ; cadena1]; %#ok<AGROW>
> end
> end
>
> and it works perfect ,but when i change the k=10 or more actually i need 243 it says this
>
> ??? Error using ==> vertcat
> CAT arguments dimensions are not consistent.
>
> Error in ==> ExtractOutp at 14
> V1 =[V1 ; cadena1]; %#ok<AGROW>
>
> and im not using vertcat ... thanks in advice :)

  When you reach k = 10, the string you are placing in V1 as its next row has one additional character in it and therefore doesn't agree with the lengths of the previous row lengths, so matlab doesn't know what to do with it. You will have to find some other method of storing strings of differing lengths, such as cell arrays, or placing them all in one row, or the like.

Roger Stafford

Subject: CAT Arguments

From: Matt Fig

Date: 13 Feb, 2009 05:05:04

Message: 3 of 6

"Rubi " <phreakadelik@hotmail.com> wrote in message
> and im not using vertcat ... thanks in advice :)


Actually, you are using vertcat when you put a semicolon in between elements in brackets. Look at these errors:

['l',('potts')'] % comma => horzcat
['l';('potts')] % semicolon => vetcat

I would do something like this if there is no desire to vectorize this:


cnt = (12 + 1) * (5 + 1);
for k = 12:-1:0
    for t = 5:-1:0
        V1{cnt} = sprintf('COMB_LIN[%d,%d]:=',[k t]);
        cnt = cnt - 1;
    end
end
char(V1) % If you need a char array instead of a cell.




PJQaGC;KQQCCD'aCGC"{ONDQQXChGoa/[VJJWWQVGhaKPIaaERRMaVaCEON

Subject: CAT Arguments

From: Rubi

Date: 13 Feb, 2009 15:52:01

Message: 4 of 6

"Matt Fig" <spamanon@yahoo.com> wrote in message <gn2v20$eog$1@fred.mathworks.com>...
> "Rubi " <phreakadelik@hotmail.com> wrote in message
> > and im not using vertcat ... thanks in advice :)
>
>
> Actually, you are using vertcat when you put a semicolon in between elements in brackets. Look at these errors:
>
> ['l',('potts')'] % comma => horzcat
> ['l';('potts')] % semicolon => vetcat
>
> I would do something like this if there is no desire to vectorize this:
>
>
> cnt = (12 + 1) * (5 + 1);
> for k = 12:-1:0
> for t = 5:-1:0
> V1{cnt} = sprintf('COMB_LIN[%d,%d]:=',[k t]);
> cnt = cnt - 1;
> end
> end
> char(V1) % If you need a char array instead of a cell.
>
>
>
>
> PJQaGC;KQQCCD'aCGC"{ONDQQXChGoa/[VJJWWQVGhaKPIaaERRMaVaCEON

Thanks a lot for the answers , i got what you mean about horzcat and vetcat :) , the code worked very well , i never tought it would work using the last number to 0 ..

and i believe this is ur sign PJQaGC;KQQCCD'aCGC"{ONDQQXChGoa/[VJJWWQVGhaKPIaaERRMaVaCEON :) jejeje thanks both replies

Subject: CAT Arguments

From: Azim

Date: 14 Apr, 2011 13:38:04

Message: 5 of 6

I had the same problem today and used the following codes which solved my problem.

The next example converts an array of java.lang.String objects into a MATLAB cell array.

strArray = java_array('java.lang.String', 3);
strArray(1) = java.lang.String('one');
strArray(2) = java.lang.String('two');
strArray(3) = java.lang.String('three');

cellArray = cell(strArray)
cellArray =
    'one'
    'two'
    'three'

for more info
http://www.mathworks.com/help/techdoc/ref/cell.html

"Roger Stafford" wrote in message <gn2d46$blh$1@fred.mathworks.com>...
> "Rubi " <phreakadelik@hotmail.com> wrote in message <gn2bsp$hfn$1@fred.mathworks.com>...
> > I need to fix this... i got this code
> >
> > V1='COMB_LIN[0,0]:=';
> > for k=0:8
> > for t=0:5
> > cadena1=sprintf('COMB_LIN[%d,%d]:=',[k t]);
> > V1 =[V1 ; cadena1]; %#ok<AGROW>
> > end
> > end
> >
> > and it works perfect ,but when i change the k=10 or more actually i need 243 it says this
> >
> > ??? Error using ==> vertcat
> > CAT arguments dimensions are not consistent.
> >
> > Error in ==> ExtractOutp at 14
> > V1 =[V1 ; cadena1]; %#ok<AGROW>
> >
> > and im not using vertcat ... thanks in advice :)
>
> When you reach k = 10, the string you are placing in V1 as its next row has one additional character in it and therefore doesn't agree with the lengths of the previous row lengths, so matlab doesn't know what to do with it. You will have to find some other method of storing strings of differing lengths, such as cell arrays, or placing them all in one row, or the like.
>
> Roger Stafford

Subject: CAT Arguments

From: Hazel

Date: 14 Apr, 2011 14:45:06

Message: 6 of 6

"Rubi " <phreakadelik@hotmail.com> wrote in message <gn2bsp$hfn$1@fred.mathworks.com>...
> I need to fix this... i got this code
>
> V1='COMB_LIN[0,0]:=';
> for k=0:8
> for t=0:5
> cadena1=sprintf('COMB_LIN[%d,%d]:=',[k t]);
> V1 =[V1 ; cadena1]; %#ok<AGROW>
> end
> end
>
> and it works perfect ,but when i change the k=10 or more actually i need 243 it says this
>
> ??? Error using ==> vertcat
> CAT arguments dimensions are not consistent.
>
> Error in ==> ExtractOutp at 14
> V1 =[V1 ; cadena1]; %#ok<AGROW>
>
> and im not using vertcat ... thanks in advice :)

I would think the neatest way would be to use a cell array. Just change the first line to:
V1={'COMB_LIN[0,0]:='};

If for some reason you really want a char array, I'd suggest just padding out the digits with 0's using:
      cadena1=sprintf('COMB_LIN[%5d,%5d]:=',[k t]);

So k & t will be padded out with preceding spaces up to 5 characters, you can use more if you think you'll ever need to iterate above 99999.

Tags for 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