Info

This question is closed. Reopen it to edit or answer.

Help with Matlab code-please

7 views (last 30 days)
Ozmando
Ozmando on 18 Feb 2019
Closed: MATLAB Answer Bot on 20 Aug 2021
Good afternoon,
I am trying to run the following code in MATLAB but get an error.
Error using *
Inner matrix dimensions must agree.
Error in vcqr (line 27)
e = y - x*bhat; % Generate residuals
Any help to fix the problem please?
Thanks
Oz
clear
load fish1
Z = [ones(111,1) stormy mixed];
X = [ones(111,1) d];
pihat = inv(Z'*Z)*(Z'*d);
tau = ['15';'25';'35';'45';'50';'55';'65';'75';'85'];
for i = 1:size(tau,1),
disp(i);
hamster = str2num(strcat('.',tau(i,:)));
boo = rq([ones(size(y)) Z*pihat],y,hamster);
[b,vc] = vcqr(boo,y,[ones(size(y)) Z*pihat],hamster);
[b,f,c,seq,conv] = mcmc_flat_fish1_mon2('iqrobj_fish',boo,vc,50000,y,[ones(size(y)),d],Z,hamster);
save(strcat('fish',tau(i,:),'_storm_v3_mon2'),'b','f','c','seq','conv');
[b,f,c,seq,conv] = mcmc_flat_fish2('iqrobj_fish',boo,vc,50000,y,[ones(size(y)),d],Z,hamster);
save(strcat('fish',tau(i,:),'_storm_v3_2'),'b','f','c','seq','conv');
end
% Here is the portion of the function related to the error:
vc = zeros(k,k);
b = zeros(k,2);
S = (1/n)*x'*x;
e = y - x*bhat; % Line 27
  5 Comments
Matt J
Matt J on 18 Feb 2019
@Ozmando,
You need to check the sizes of bhat and x at the moment the error actually occurs. To do this, execute
>>dbstop if error
at the command line and then re-run the code.
Matt J
Matt J on 18 Feb 2019
Ozmando commented:
Thanks Matt.
seems to be issues with size of x abd bhat. Will go through code again to try to figure out the source.
oz

Answers (0)

This question is closed.

Community Treasure Hunt

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

Start Hunting!