Matrix dimension must agree
Mostra commenti meno recenti
Hi,
I need some help with troubleshooting this code. It keeps giving me the error
Error in Assigment2problem1function (line 16)
It11=I0f.*10.^(-A1);
Error using .*
Matrix dimensions must agree.
function [ Absorbance1,Absorbance2 ] = Assigment2problem1function(I0,E1,E2,l,Nrep)
%I0=100000, E1=10000, E2=20000, l=1, Nrep=3
% Detailed explanation goes here
% A = ECl beer-lambert law
% A = -log T = -log(It/Io)=log(I0)-log(It)
% A = Absorbance
%It = Intensity of Transmitted photons
%I0 = Initial Intensity of photons
% Assigment2problem1function(100000,10000,20000,1,3)
C=10:10:50*(10^-6);
SD=sqrt(I0);
for i=1:Nrep
I0f=I0+rand(1,Nrep)*SD;
A1=E1*C*l;
It11=I0f.*10.^(-A1);
SD21=sqrt(It11);
It12=It11+SD21.*rand(1,1);
Absorbance1=log(I0)-log(It12)
A2=E2*C*l;
It21=I0f.*10.^(-A2);
SD21=sqrt(It21);
It22=It21+SD21.*rand(1,1);
Absorbance2=log(I0)-log(It22)
end
Risposta accettata
Più risposte (1)
The error message is telling you the problem. In the line below, you're multiplying two matrices I0f and 10.^(-a1). If you look at their sizes (see example below), you will see that they have different sizes.
It11=I0f.*10.^(-A1);
% Look at sizes
size(I0f)
size(10.^(-A1)
There are 2 types of matrix multiplications. When you include the dot (.*), you are multiplying two matrices element-wise. So A(1,1) will be multiplied by B(1,1). The matricies must be the same size. Here's an example:
[1 2 3; 4 5 6] .* [1 1 1; 2 2 2]
ans =
1 2 3
8 10 12
Without the dot (*), you're doing a standard matrix multiplication where the the sizes must be [n, m] and [m, p]. Here's an example
[1 2 3; 4 5 6] * [1 1; 2 2; 3 3]
ans =
14 14
32 32
Depending on which type of multiplication you're seeking, you'll need to make sure the sizes of the matricies are appropriate.
1 Commento
Chanaka Navarathna
il 2 Feb 2019
Categorie
Scopri di più su Signal Generation, Analysis, and Preprocessing in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!