I need help to correct this code. How do I get this error corected (Incorrect dimensions for matrix multiplication. Check that the number of columns in the first matrix matches the number of rows in the second matrix.)?

function [SNRF, SNRUV] = SNG(noOfRuns)
NoOfPhotons = 1000000;
Q = 0.6;
b = 1;
E = 10000;
c = 0.00001;
stD = 1000;
Mean = 1000000;
for i = 1:noOfRuns
extPhotons = NoOfPhotons + randn(noOfRuns,1) * stD;
F = 0.01*extPhotons*2.303*E*b*c*Q;
stD2 = sqrt(F);
detPhotonsF = F + randn(noOfRuns,1)* stD2;
mean_detPhotonsF = mean(detPhotonsF);
stdev = std(detPhotonsF);
SNGF (i) = mean_detPhotonsF/stdev
end

댓글 수: 2

What's wrong with it? Please provide more details, including a complete error message, if available.
O n running the code, this particular line detPhotonsF = F + randn(noOfRuns,1)* stD2;
is returning error: Incorrect dimensions for matrix multiplication. Check that the number of columns in the first matrix matches the number of rows in the second matrix.

댓글을 달려면 로그인하십시오.

 채택된 답변

I believe the error is in using matrix multiplication, versus element multiplication. You have:
detPhotonsF = F + randn(noOfRuns,1)* stD2;
which is causing the code to try and multiply the matrix of randn(noOfRuns,1) by the matrix of stD2. I'm assuming you want to multiply the corresponding elements, which would be the following:
detPhotonsF = F + randn(noOfRuns,1) .* stD2; % Using .* or ./ or .^ conducts elementwise operations

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

태그

질문:

2019년 2월 6일

답변:

2019년 2월 6일

Community Treasure Hunt

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

Start Hunting!

Translated by