How can I fix this error - "Error using / Matrix dimensions must agree"
显示 更早的评论
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 个评论
the cyclist
2017-1-26
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
2017-11-19
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;
采纳的回答
更多回答(1 个)
the cyclist
2017-1-26
编辑:the cyclist
2017-1-26
6 个投票
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 个评论
Diah Junaidi
2017-11-27
How about this sir?? I dont know what should i do :( would you please check mine sir ? :(
the cyclist
2017-11-27
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.
类别
在 帮助中心 和 File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!