Thread Subject: please ,any help in adding rows in matrices

Subject: please ,any help in adding rows in matrices

From: Haitham Tahbub

Date: 23 Nov, 2009 11:43:01

Message: 1 of 6

Hi all,

i want to create an empty matrix that i want to fill it with rows because later i want to compare between any two rows ,

for example if i have a matrix called 's' and i have elements in a matrix of (1X4) called
'b' , so i want to enter the elements of b in the first row in matrix 's', notice that if i have any other matrix with one row also called 'c' and its size is (1X5) i want also to add the elements of this matrix in the second row for example , and if there is any position have no element in it i want to put zero because we can't leave it empty.
i tried to create a zeros matrix called 's' but this way didn't succeed

example tried:-

x=zeros(9,9);
b=[1 2 4 3 5 5];
x(1,:)=[b];

%%%%%%%%%%%%%%%%%%
this is the result
??? Subscripted assignment dimension mismatch.
Error in ==> testing at 14
x(1,:)=[b];
%%%%%%%%%%%%%%%%%%%%
===========================================

the second way i tried is to create an empty matrix called 's' and i tried to enter rows in it with different number of column but with one row,
it succeeded in putting the first row but the second row with different number of column failed to be entered in the matrix:

ex:
x=[];
b=[2 4 5 6];
x=[x;b]
c=[5 4 6 8 9];
x=[x;c];

%%%%%%%%%%%%%%%%%%%result:-
x =

     2 4 5 6

??? Error using ==> vertcat
CAT arguments dimensions are not consistent.
Error in ==> testing at 15
x=[x;c];

%%%%%%%%%%%%%%%%%%%%%%

please help me,

Subject: please ,any help in adding rows in matrices

From: ImageAnalyst

Date: 23 Nov, 2009 12:21:22

Message: 2 of 6

OK, you have a matrix s with 9 columns. And you want to put 6 numbers
into those 9 columns. Which 6 columns, out of those 9, do you want to
put them into? The 6 left most columns? The 6 rightmost columns?
Somewhere else?

Subject: please ,any help in adding rows in matrices

From: Haitham Tahbub

Date: 23 Nov, 2009 13:07:03

Message: 3 of 6

ImageAnalyst <imageanalyst@mailinator.com> wrote in message <ed8b0535-cb44-402c-812a-0dce9fded3b6@f20g2000vbl.googlegroups.com>...
> OK, you have a matrix s with 9 columns. And you want to put 6 numbers
> into those 9 columns. Which 6 columns, out of those 9, do you want to
> put them into? The 6 left most columns? The 6 rightmost columns?
> Somewhere else?

i want to put it into:
the 6 left most columns out of those 9 and the left must be zeroes

please help me ,
thanks

Subject: please ,any help in adding rows in matrices

From: Jos

Date: 23 Nov, 2009 13:14:04

Message: 4 of 6

"Haitham Tahbub" <the_mummy_n1@hotmail.com> wrote in message <hedsg5$q73$1@fred.mathworks.com>...
> Hi all,
>
> i want to create an empty matrix that i want to fill it with rows because later i want to compare between any two rows ,
>
> for example if i have a matrix called 's' and i have elements in a matrix of (1X4) called
> 'b' , so i want to enter the elements of b in the first row in matrix 's', notice that if i have any other matrix with one row also called 'c' and its size is (1X5) i want also to add the elements of this matrix in the second row for example , and if there is any position have no element in it i want to put zero because we can't leave it empty.
> i tried to create a zeros matrix called 's' but this way didn't succeed
>
> example tried:-
>
> x=zeros(9,9);
> b=[1 2 4 3 5 5];
> x(1,:)=[b];
>
> %%%%%%%%%%%%%%%%%%
> this is the result
> ??? Subscripted assignment dimension mismatch.
> Error in ==> testing at 14
> x(1,:)=[b];
> %%%%%%%%%%%%%%%%%%%%
> ===========================================
>
> the second way i tried is to create an empty matrix called 's' and i tried to enter rows in it with different number of column but with one row,
> it succeeded in putting the first row but the second row with different number of column failed to be entered in the matrix:
>
> ex:
> x=[];
> b=[2 4 5 6];
> x=[x;b]
> c=[5 4 6 8 9];
> x=[x;c];
>
> %%%%%%%%%%%%%%%%%%%result:-
> x =
>
> 2 4 5 6
>
> ??? Error using ==> vertcat
> CAT arguments dimensions are not consistent.
> Error in ==> testing at 15
> x=[x;c];
>
> %%%%%%%%%%%%%%%%%%%%%%
>
> please help me,

Take a look at my PADCAT function:
http://www.mathworks.com/matlabcentral/fileexchange/22909

hth
Jos

Subject: please ,any help in adding rows in matrices

From: Haitham Tahbub

Date: 23 Nov, 2009 14:51:19

Message: 5 of 6


>
> Take a look at my PADCAT function:
> http://www.mathworks.com/matlabcentral/fileexchange/22909
>
> hth
> Jos
thanks to you but i wanted to use the matlab techniques without any additional functions ......
but i want to ask you if i can change in the function to insert zeroes instead of NaN

i am waiting your reply as soon as possible
and thanks to you

Subject: please ,any help in adding rows in matrices

From: ImageAnalyst

Date: 23 Nov, 2009 21:35:12

Message: 6 of 6

On Nov 23, 8:07 am, "Haitham Tahbub" <the_mummy...@hotmail.com> wrote:
> i want to put it into:
> the 6 left most columns out of those 9 and the left must be zeroes
>
> please help me ,
> thanks
--------------------------------------------------------
I think when you use "left" the second time, you really mean
"remaining elements in the row on the right" rather than left (as in
right/left). Anyway, this will do it:

x = zeros(9,9);
b = [1 2 4 3 5 5]
x(1,1:length(b))=b

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

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.

Tag Activity for This Thread
Tag Applied By Date/Time
adding rows Haitham Tahbub 23 Nov, 2009 06:44:04
rssFeed for this Thread

Contact us at files@mathworks.com