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

H ZETT M
H ZETT M 2017년 6월 7일
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
Adam
Adam 2017년 6월 7일
Put a breakpoint in on his machine and see if the sizes of the arrays are the same as on yours.
Rik
Rik 2017년 6월 7일
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.

댓글을 달려면 로그인하십시오.

 채택된 답변

Jan
Jan 2017년 6월 7일

2 개 추천

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.

추가 답변 (1개)

Andrei Bobrov
Andrei Bobrov 2017년 6월 7일

0 개 추천

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

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

제품

질문:

2017년 6월 7일

답변:

Jan
2017년 6월 7일

Community Treasure Hunt

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

Start Hunting!

Translated by