A(I) = B, the number of elements in B and I must be the same.
Info
This question is closed. Reopen it to edit or answer.
Show older comments
Can someone please help me with this error message. I do not understand what is wrong with my code. Thank you again in advance.
??? In an assignment A(I) = B, the number of elements in B and I must be the same.
Error in ==> DeclineCurveMCMC3 at 171 theta(i+1) = theta_ast;
I have attached the m file as was recommended, I apologize for the previous unreadable code format.
1 Comment
Geoff Hayes
on 27 May 2014
Please format your code to make it readable by following the tutorial at http://www.mathworks.com/matlabcentral/answers/13205-tutorial-how-to-format-your-question-with-markup.
Note, rather than pasting the block of code into your question body, you could have just attached the m file.
Answers (1)
Geoff Hayes
on 27 May 2014
The error is at line 171 of your code (as per the error message)
theta(i+1) = theta_ast;
You could debug this to see what is happening. Put a breakpoint at this line and re-run your function. When you get to the breakpoint, what is theta? what is theta_ast? You should notice that theta_ast is an empty matrix which was assigned as such in a previous line
theta_ast = proposal_PDF([]);
What is the code trying to accomplish in the above line? What do you want theta_ast to be? I suppose it should be a scalar of some kind (given the assignment to theta) but how do you intend to calculate this value?
4 Comments
Paul Caplis
on 27 May 2014
Geoff Hayes
on 27 May 2014
Okay but the code is using square brackets which indicates empty and when using empty as an index, nothing will be returned. For example, if
>> proposal_PDF = 0.4546
proposal_PDF =
0.4546
then
>> theta_ast = proposal_PDF([])
theta_ast =
[]
So the code is (kind of) saying take nothing from proposal_PDF and assign that nothing to theta_ast. And so theta_ast is just an empty matrix and when it is assigned to an element of theta the error arises. If proposal_PDF is just a single value, then do a straight assignment
>> theta_ast = proposal_PDF
or
>> theta_ast = proposal_PDF(1)
Paul Caplis
on 27 May 2014
Edited: Paul Caplis
on 27 May 2014
Geoff Hayes
on 27 May 2014
Glad to have been of help!
This question is closed.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!