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:
Matrix subtraction

Subject: Matrix subtraction

From: Theo Kalfas

Date: 29 Jan, 2009 10:36:02

Message: 1 of 8

Hi!
I have a matrix K 1x281.
How can i find the subtraction of the K(2)-k(1),K(3)-k(2)....K(281)-K(280)?
Thank you!!!

Subject: Matrix subtraction

From: John D'Errico

Date: 29 Jan, 2009 10:54:01

Message: 2 of 8

"Theo Kalfas" <k_thodoros@yahoo.gr> wrote in message <gls0qh$83l$1@fred.mathworks.com>...
> Hi!
> I have a matrix K 1x281.
> How can i find the subtraction of the K(2)-k(1),K(3)-k(2)....K(281)-K(280)?
> Thank you!!!

This could be a very DIFFicult problem, to
DIFFerence your data as you wish. I would
DIFFinitely look in matlab for a function that
would do it for you.

Ok, so I was kidding above. But there is a hint
provided. Or better yet, use the lookfor function
to answer these questions in the future. For
example, try this in MATLAB:

lookfor difference

HTH,
John

Subject: Matrix subtraction

From: Tiago Silva

Date: 29 Jan, 2009 11:03:27

Message: 3 of 8

help diff

Subject: Matrix subtraction

From: Theo Kalfas

Date: 29 Jan, 2009 11:12:02

Message: 4 of 8

"John D'Errico" <woodchips@rochester.rr.com> wrote in message <gls1s9$ivu$1@fred.mathworks.com>...
> "Theo Kalfas" <k_thodoros@yahoo.gr> wrote in message <gls0qh$83l$1@fred.mathworks.com>...
> > Hi!
> > I have a matrix K 1x281.
> > How can i find the subtraction of the K(2)-k(1),K(3)-k(2)....K(281)-K(280)?
> > Thank you!!!
>
> This could be a very DIFFicult problem, to
> DIFFerence your data as you wish. I would
> DIFFinitely look in matlab for a function that
> would do it for you.
>
> Ok, so I was kidding above. But there is a hint
> provided. Or better yet, use the lookfor function
> to answer these questions in the future. For
> example, try this in MATLAB:
>
> lookfor difference
>
> HTH,
> John
Oh yesss!!!!I have a solution for the most diffucult problem in MATLAB!!!Thank you very much John!!:-))

Subject: Matrix subtraction

From: Theo Kalfas

Date: 29 Jan, 2009 14:19:01

Message: 5 of 8

Now i have a new question!!!
I have 3 matrixes 1x280,1x280,1x281 which my program gives me when i run a loop for.I want to add these 3 matrixes and of course Matlab gives me the error:
??? Error using ==> +
Matrix dimensions must agree.
Is there any way to do this sum?The last value(281) is not important...I thought to open the array editor and delete the last cell...But if i want to change a value in my program then i'll spend time to delete every time the last cell and after to add the matrixes.

Subject: Matrix subtraction

From: John D'Errico

Date: 29 Jan, 2009 14:49:01

Message: 6 of 8

"Theo Kalfas" <k_thodoros@yahoo.gr> wrote in message <glsdsl$gh$1@fred.mathworks.com>...
> Now i have a new question!!!
> I have 3 matrixes 1x280,1x280,1x281 which my program gives me when i run a loop for.I want to add these 3 matrixes and of course Matlab gives me the error:
> ??? Error using ==> +
> Matrix dimensions must agree.
> Is there any way to do this sum?The last value(281) is not important...I thought to open the array editor and delete the last cell...But if i want to change a value in my program then i'll spend time to delete every time the last cell and after to add the matrixes.

Please open a new thread for new questions.

Since it does not make sense to add two vectors
with different lengths, do you really expect not
to get an error?

You can delete the last element from a vector.

vec(end) = [];

Or you can just add the first 280 elements from
that vector

vec1 + vec2 + vec3(1:280)

John

Subject: Matrix subtraction

From: Steven Lord

Date: 29 Jan, 2009 14:49:37

Message: 7 of 8


"Theo Kalfas" <k_thodoros@yahoo.gr> wrote in message
news:glsdsl$gh$1@fred.mathworks.com...
> Now i have a new question!!!
> I have 3 matrixes 1x280,1x280,1x281 which my program gives me when i run a
> loop for.I want to add these 3 matrixes and of course Matlab gives me the
> error:
> ??? Error using ==> +
> Matrix dimensions must agree.
> Is there any way to do this sum?The last value(281) is not important...I
> thought to open the array editor and delete the last cell...But if i want
> to change a value in my program then i'll spend time to delete every time
> the last cell and after to add the matrixes.

x = rand(1, 280);
y = rand(1, 280);
z = rand(1, 281);
minSz = min([size(x, 2) size(y, 2) size(z, 2)]);
q = x(1:minSz) + y(1:minSz) + z(1:minSz);

--
Steve Lord
slord@mathworks.com

Subject: Matrix subtraction

From: Theo Kalfas

Date: 3 Feb, 2009 13:38:02

Message: 8 of 8

I have a matrix A(280x1) and B(280x27).How can i do the subtraction A-B(every column of B)?
Thank you.

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