Effacer les filtres
Effacer les filtres

Disagreement of Matrix dimension

2 vues (au cours des 30 derniers jours)
Anandh
Anandh le 4 Août 2011
Hello Friends,
I have executed the following codes:
X=[8.3 13.9 12.5 22.2 8.3 11.1 18.1 11.1 6.9 6.9 6.9 19.4 9.7 4.2 5.6 12.5 11.1 6.9 8.3 8.3 13.9 9.7 6.9 6.9 8.3 5.6 12.5 4.2 18.1 11.1 4.2 8.3 12.5 15.3 5.6 6.9 13.9 13.9 18.1 12.5 15.3 29.2 36.1 30.6 22.2 40.3 41.7 52.8 50 52.8 61.1 55.6 72.2 69.4 68.1 68.1 76.4 94.4 77.8 101.4 81.9 73.6 93.1 76.4 48.6 52.8 41.7 44.4 43.1 25 26.4 19.4 25 19.4 16.7 13.9 8.3 15.3 5.6 5.6 5.6 5.6 9.7 6.9 2.8 8.3 9.7 8.3 11.1 12.5 15.3 8.3 13.9 4.2 16.7 5.6 8.3 16.7 4.2 11.1 2.8 8.3 5.6 8.3 4.2 11.1 12.5 8.3 8.3 9.7 13.9 15.3 19.4 20.8 25 23.6 25 25 25 33.3 26.4 23.6 27.8 19.4 22.2 19.4 23.6 26.4 15.3 23.6 15.3 26.4 13.9 9.7 15.3 11.1 11.1 18.1 9.7 16.7 18.1 9.7 11.1 22.2 18.1 13.9 19.4 20.8 18.1 13.9 15.3 19.4 13.9 16.7 20.8 12.5 18.1 15.3 15.3 12.5 8.3 12.5 20.8 15.3 15.3 12.5 13.9 9.7 18.1 8.3 19.4 16.7 12.5 12.5 13.9 6.9 9.7 11.1 16.7 5.6 8.3 11.1 4.2 12.5 2.8 12.5 11.1 8.3 9.7 8.3 8.3 18.1 12.5 11.1 8.3 9.7 6.9 12.5 5.6 8.3 0];
M=2;
N = length( X );
Z = ones(N,M) * 1/M; % indicators vector
P = zeros(N,M); % probabilities vector for each sample and each model
t = ones(1,M) * 1/M; % distribution of the gaussian models in the samples
u = linspace(min(X),max(X),M); % mean vector
sig2 = ones(1,M) * var(X) / sqrt(M); % variance vector
C = 1/sqrt(2*pi); % just a constant
Ic = ones(N,1); % - enable a row replication by the * operator
Ir = ones(1,M); % - enable a column replication by the * operator
Q = zeros(N,M);
thresh = 1e-3;
step = N;
last_step = inf;
iter = 0;
min_iter = 10;
when I try to execute the following code,
P = C ./ (Ic*sqrt(sig2)) .* exp( -((X*Ir -Ic*u).^2)./(2*Ic*sig2));
am getting this error:
?? Error using ==> mtimes
Inner matrix dimensions must agree.
The problem I have identified with that code,in particular (X*Ir)is both are matrix but of different sizes, say X = 1R&201C and Ir=1R&1C.
How to handle these different size matrices?
Please help me out.
Also suggest me some alternate codes. Thanks.
kra/-
  2 commentaires
Oleg Komarov
Oleg Komarov le 4 Août 2011
Please format the code with the {} button, will increase the chance of an prompt answer.
Anandh
Anandh le 4 Août 2011
thanks Oleg.

Connectez-vous pour commenter.

Réponse acceptée

Andreas Goser
Andreas Goser le 4 Août 2011
How to debug this:
1. Format the code in a way Oleg asked for. You help others to help you.
2. If you have a matrix dimension error in one line, split the line into sub-operations in oder to see where it fails, e.g.
P = C ./ (Ic*sqrt(sig2)) .* exp( -((X*Ir -Ic*u).^2)./(2*Ic*sig2)); % fails
exp( -((X*Ir -Ic*u).^2)./(2*Ic*sig2)) % fails
-((X*Ir -Ic*u).^2) % fails
X*Ir % fails - there must be at least one cause
3.
>> whos X Ir
Name Size Bytes Class Attributes
Ir 1x2 16 double
X 1x201 1608 double
-> Now it is clear. 1x201 * 1x2 - > That's not going to work. The question still is, what is it that you need to achieve. Just because I could tell you a working operation, I can't tell you what makes sense.
  3 commentaires
Oleg Komarov
Oleg Komarov le 4 Août 2011
201x1 * 1x2 = 201x2: basics of matrix multiplication, more on wikipedia.
I would suggest to do: (1x2)' * 1x201 = 2x201. Transposing a smaller matrix is more convenient...but it depends also on subsequent operations which at the moment I can't read.
Andreas Goser
Andreas Goser le 4 Août 2011
I would like to refrain from suggesting a certain operation / implementation.
See the examples in the doc here: http://www.mathworks.com/help/techdoc/ref/arithmeticoperators.html
It lists all the ways to multiply two vectors.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Tags

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by