How can I fix this error - "Error using / Matrix dimensions must agree"
Afficher commentaires plus anciens
I am trying to get values for y with T in the range 800 - 1100. the function I have called antoine works for single values but i get the error seen in the screen shot when i try to use the linspace command. Any idea how i can fix this?
2 commentaires
the cyclist
le 26 Jan 2017
For future reference, it is better to upload the code itself, rather than a screenshot of the code. That way, we can paste it into MATLAB directly.
Anila Khan
le 19 Nov 2017
When i run this program it give me error. Error screen shoot attach here please guide me.
clc clear all close all m=30; n=30; snr=20; %Generation of corelation matrix
R=eye(m,m) R(m+1:m+1:end)=0.2; R(2:m+1:end)=0.2;
generations=100:100:500 no_ofDataRuns=500 for gen=1:length(generations) genError=0 for i=1:no_ofDataRuns B=randsrc(m,n) tx=randsrc(1,m) r=awgn(tx,snr) FF=Fit_PSO(r, B, R, m) for cyc=1:generations(gen) Pb=FF(:,2:end) %pb=B; Gb=FF(1,2:end) V=zeros(m,n) for k=1:m C=(Pb(k,:) - B(k,:)); D=(Gb - B(k,:)); V(k,:)=V(k,:) + rand().*C + rand().*D; %V(k,:)=V(k,:) + rand().*(Pb(k,:) - B(k,:)) + rand().*(Gb - B(k,:));
end
for a=1:m
for b=1:n
S(a,b)=1/(1+exp(-V(a,b)))
if S(a,b)>rand()
B(a,b)=1
else
B(a,b)=-1
end
end
end
updated_fitness=Fit_PSO(r,B,R,m)
updated_fitness_error=updated_fitness(1,2:end)
Error(cyc)=pdist([updated_fitness_error;tx],'hamming')
end
genError=(genError+Error(cyc))
end
BER(gen)=genError/[generations(gen)*no_ofDataRuns]
end semilogy(generations,smooth(BER),'Color',[0 0 1]) xlabel('Number of cycles'); ylabel('Bit Error Rate'); txt = strcat('BER Vs generations with ',int2str(snr),'db AWGN') title('BER Vs NOC') grid on; hold on;
Réponse acceptée
Plus de réponses (1)
the cyclist
le 26 Jan 2017
Modifié(e) : the cyclist
le 26 Jan 2017
6 votes
You need to use element-wise division, not matrix division.
Use "./" in place of "/"
You are similarly going to want ".^" rather than just "^" for raising to a power.
2 commentaires
Diah Junaidi
le 27 Nov 2017
How about this sir?? I dont know what should i do :( would you please check mine sir ? :(
the cyclist
le 27 Nov 2017
Rather than putting a comment a question that is nearly a year old, I suggest that you create a new question. Attach your code (as you did here), tell us the full text of any error messages you are getting, and ask specific questions.
Catégories
En savoir plus sur Matrix Indexing dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!