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

New to MATLAB?

Thread Subject:
Error using ==> mldivide

Subject: Error using ==> mldivide

From: William

Date: 8 Dec, 2011 02:11:08

Message: 1 of 2

I wanted to run a fairly simple program and thought it would be easy, however I'm having trouble. I thought I troubleshooted (is that the correct past tense, troubleshot?) the code but can't seem to get it.

I'm sure you pros will have it figured it out in seconds...

function ch2_23 (t)
%created by so and so

k = 8.62*10^(-5);

y = 1/(1+exp(e_minus_ef ./ (k.*t) ));


The error I get when I run the script is....

??? Error using ==> mldivide
Matrix dimensions must agree.

Error in ==> ch2_23 at 8
y = 1/(1+exp(e_minus_ef ./ (k.*t) ));


All help will be greatly appreciated!

Thank you.

Subject: Error using ==> mldivide

From: Roger Stafford

Date: 8 Dec, 2011 06:16:09

Message: 2 of 2

"William" wrote in message <jbp6bs$23j$>...
> e_minus_ef=[-0.2:0.01:0.2];
> y = 1/(1+exp(e_minus_ef ./ (k.*t) ));
> ??? Error using ==> mldivide
> Matrix dimensions must agree.
- - - - - - - - -
  The mistake is in the use of '/' in the first part of the line

 y = 1/(1+exp(e_minus_ef ./ (k.*t) ));

Since the denominator is not a scalar, this division is interpreted as matlab's "matrix division" in which the result will have as many rows as the numerator and as many columns as there are rows in the denominator, and in which the numerator and denominator must have equal numbers of columns. The latter violation is the source of your error message. This holds true even with a scalar numerator. You are lucky your denominator wasn't a column vector for which there would have been no error message but a very mystifying row vector result. You should read all about matrix division in the pertinent Mathworks' documentation.

  I think you meant to have 1 divided by each element of the denominator which is quite a different operation. For this you should use './' :

 y = 1./(1+exp(e_minus_ef ./ (k.*t) ));

Roger Stafford

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