Different results using .* on two computers

Hello
I am trying to run a MATLAB program, that my collegue wrote. It runs fine on his computer, however quite far down in the program i get an error using .* stating "matrix dimensions must agree". The operator is for multiplying a 1x1001 double with a 5x1001 double.
Any idea why it runs fine on his computer but not on mine? MATLAB versions are the same and the program initiates with: clc; clear all; close all; clear memory;format rational;

3 Commenti

Are you sure that the matrices are the same ? I am also not sure how you want to multiply them. Since they are not the same size and it doesnt fit at all (at least from what I tested).
Have you also check if you call any functions in between ? Maybe one computer is using old files that you did not change
Put a breakpoint in on his machine and see if the sizes of the arrays are the same as on yours.
Try running it on the other computer and use a breakpoint to find out what sizes the variables are when he runs it.
Does it load data from somewhere that might be different between the machines? Are there helper functions on one computer, where the other computer uses a built-in with the same name? Those two are problems that I frequently encounter when debugging code.

Accedi per commentare.

 Risposta accettata

The elementwise multiplication of a 1x1001 and a 5x1001 works since Matlab 2016b with the implicite auto-expanding. The result is a 5x1001. In earlier versions this code fails.
Also you are convinced that you process the same data with the same Matlab versions, this is not the fact. Obviously there is an important difference you are not aware of: Either the Matlab versions are different, or the data, or maybe the code.
This is a bad start:
clc; clear all; close all; clear memory;format rational;
There is no reason to delete all loaded functions from the memory. Reloading them from the slow disk is a waste of time and energy. Closing all files and figure is strange also. Better use specific methods to close them on demand only.
I see, that many beginners start their scripts with such a brute clearing. Using functions instead keeps the workspace clean without wasting time. Matlab's JIT acceleration has more power inside functions, such that this approach is usually faster also.

Più risposte (1)

use
bsxfun(@times,a,b) % here a - double array [1 x 1001], b - double array [5 x 1001]

Prodotti

Richiesto:

il 7 Giu 2017

Risposto:

Jan
il 7 Giu 2017

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by