Error using .* in Matlab R2014a?

Dear all,
I am new to Matlab and I am trying to run a series of scripts that were written few years ago to reproduce the data set created at that time. I am using version R2014a.
To obtain the desired output I should run 4 scripts one after the other. The first script is giving me no problems, but the second one is giving me these errors (the first 3 lines are in orange, the last 4 in red):
Warning: Variable 'samplename' originally saved as a string cannot be instantiated as an object and will
be read in as a uint32.
> In ro2_gen_fossil_emis_v2 at 64
Error using .*
Matrix dimensions must agree.
Error in ro2_gen_fossil_emis_v2 (line 85)
Emis = 1./tau.*(foss_CH4_burden);
I try to contact the person that originally wrote the scripts in a R2019a version of Matlab. We tried the same procedure and he could run the scripts with no problems. We double checked the error in line 85 and apparently the lines are identical. I even try to copy paste his line on my script, but the problem was still appearing.
Does anyone have any idea about what could cause this problem when running in R2014a instead of R2019a?
Unfortunately I have no means to get a newer version of Matlab.
Thanks everyone for helping!
Mat

 采纳的回答

Torsten
Torsten 2022-10-15

0 个投票

Implicit expansion could be the reason. It was introduced Matlab Release 2016b.
What are the sizes of "tau" and "foss_CH4_burden" ?

9 个评论

tau is 10000x1 double and foss_CH4_burden is 10000x1x18 double.
Can this be enough to give the error?
Yes, pointwise multiplication of arrays was only defined for arrays of equal size (except for the case where one of the arrays was a scalar). Here, you multiply arrays of different sizes.
Imagine
1./tau = [2; 4 ;6]
and
foss_CH4_burden = [1 2 3; 4 5 6; 7 8 9]
So you want MATLAB to do
Emis = [2*1 2*2 2*3 ; 4*4 4*5 4*6 ; 6*7 6*8 6*9]
Emis = 3×3
2 4 6 16 20 24 42 48 54
when you write
Emis = [2; 4 ;6].*[1 2 3; 4 5 6; 7 8 9]
Emis = 3×3
2 4 6 16 20 24 42 48 54
?
That's only possible for MATLAB Releases after 2016 a.
I see. So I need an extra dimension in tau. Is it possible and feasible to add a dimension to the tau matrix?
just one line above tau is defined as:
tau = 10.05 + 0.5.*randn(10000,1)
It is my understanding that this is creating tau as 10000x1. Is it maybe enough to add something in this line to end with a 10000x1x18?
I hope my questions are not too naive.
Thanks,
Mat
Use bsxfun instead. This should work in your release.
Emis = bsxfun(@times,1./tau,foss_CH4_burden)
I will give it a try asap and give an update. Thanks for now!
I just gave it a try. It's working!! Thanks a lot!
now I was trying to run the 3rd script and another error occurred. Because no error was ecountered when run on the 2019 version, do you by chance have an idea if the same is ture for the 2014 version and this new error? Here:
Undefined function 'histogram' for input arguments of type 'double'.
Error in ro3_non_ss_ODB (line 50)
histogram (dt)
I think this should be just a command to get an hystogram of dt as an output, but I am not sure.
dt is defined in the code as:
dt = -(BO_age_resamp-OD_age_resamp);
but here no error was encountered, so I assume everything was all right.
Thanks!
Mat
Please click the "Accept this answer" link to award @Torsten "reputation points" for helping you. Thanks in advance. 🙂
Sure! I will do it immediately! Should I start a new topic for my next question?
Torsten
Torsten 2022-10-15
编辑:Torsten 2022-10-15
You should read the documentation of "histogram" for the MATLAB version with which you want the code to work.
It's even possible that the "histogram" function doesn't exist for your MATLAB version. It was Introduced in R2014b.

请先登录,再进行评论。

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 Performance and Memory 的更多信息

产品

版本

R2014a

Community Treasure Hunt

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

Start Hunting!

Translated by