My code runs well on Windows but gets errors on Mac

Hi, my code works well on Windows, but when I run it on Mac it gets errors. For example:
invSig2 = gamrnd(newnu2, 1./newS2):: Input arguments must have the same size!
I thought the problem could be 1./newS2 does not work on Mac, then I replaced
invSig2 = gamrnd(newnu2, rdivide(1,newS2))
but the problem was not solved. Do you have any idea about common errors between Mac and Windows. Thanks you very much.

 採用された回答

John D'Errico
John D'Errico 2016 年 9 月 3 日

1 投票

This is not an OS problem. This is a problem of you not having the correct inputs for the function you are using.
1./newS2
would ABSOLUTELY work on the Mac.
LOOK AT THE SIZES OF YOUR VARIABLES. READ THE ERROR MESSAGE! It is telling you these variables were not the same size when you ran this on the Mac. I will postulate that when you tried this on your Mac, your variables were not the expected size or shape.
Running on a Mac: (R2016a)
newnu2 = 1:4;
newS2 = rand(1,4);
invSig2 = gamrnd(newnu2, 1./newS2)
invSig2 =
2.1017 3.3346 2.5989 3.4549

5 件のコメント

Nguyen Bao
Nguyen Bao 2016 年 9 月 3 日
Thanks John, your example does not work on my Mac (R2015a) Error using gamrnd (line 63) gamrnd:: Input arguments must be column vectors Of course, if I revise : gamrnd(newnu2',1./newS2') will be OK. But the thing is why on Windows there is no problem.
Nguyen Bao
Nguyen Bao 2016 年 9 月 3 日
Just tested an example from Mathworks: n1 = gamrnd(1:5,6:10) Error using gamrnd (line 63) gamrnd:: Input arguments must be column vectors
John D'Errico
John D'Errico 2016 年 9 月 3 日
So you have an older release of MATLAB. Apparently gamrnd was more restrictive on an older release.
When you see an error like that, check the sizes of your arguments. Read the help.
I was thinking on several questions today that Answers should require you to state the release of MATLAB you are running. That would resolve many issues.
Walter Roberson
Walter Roberson 2016 年 9 月 3 日
... and that in turn suggests that on Windows you might be running a newer release than you are on OS-X, taking advantage of a feature that did not exist in the older version.
Note: you should use
gamrnd(newnu2(:), 1./newS2(:))
using (:) rather than ' because ' has a different meaning (conjugate transpose, not just transpose.)
Nguyen Bao
Nguyen Bao 2016 年 9 月 4 日
Thank John and Walter very much. I just updated R2016a and the problem solved.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeEconometrics Toolbox についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by