Inner dimensions must agree problem

When running this I get the error message:
Error using *
Inner matrix dimensions must agree.
Error in opticaldepth (line 14)
tau(iz,il) = tau(iz,il) + s_abs(il,ij).*sum((Nj(iz:end)*z),ij);
Error in task2 (line 61)
tau = opticaldepth( z,lambda,Nj,s_abs );
It does not work using .* instead.
I get that dimensions doesnt agree, but i thought it did. Can anyone see a solution?
function [ tau ] = opticaldepth( z,lambda,Nj,s_abs )
load('msis20120223_12.dat.txt') % 621x3 matrix
z = msis20120223_12_dat(:,1);
nN2 = msis20120223_12_dat(:,2);
nO = msis20120223_12_dat(:,3);
nO2 = msis20120223_12_dat(:,4);
Nj = [ nN2(:,1) nO(:,1) nO2(:,1) ];
load('PhotAbs.dat.txt')
lambda = PhotAbs_dat(:,1); % 20x3 matrix
sigN2 = PhotAbs_dat(:,2);
sigO = PhotAbs_dat(:,3);
sigO2 = PhotAbs_dat(:,4);
s_abs = [ sigN2(:,1) sigO(:,1) sigO2(:,1) ];
nz = length(z); %621
nl = length(lambda); %20
dz = gradient(z);
tau = zeros(nz,nl);
for il = 1:nl,
for iz = 1:nz,
for ij = 1:3,
tau(iz,il) = tau(iz,il) + s_abs(il,ij).*sum((Nj(iz:end)*z),ij);
end
end
end
tau = opticaldepth( z,lambda,Nj,s_abs );

답변 (1개)

James Tursa
James Tursa 2015년 5월 18일

1 개 추천

What are you trying to do here?
Nj(iz:end)*z
Nj is a matrix with 3 columns and you are using linear indexing into it, which is probably not what you intended.

댓글 수: 1

kdyrland
kdyrland 2015년 5월 18일
I'm trying to implement an integral, Nj*dz over z_0 to z_max.

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

질문:

2015년 5월 18일

편집:

2015년 5월 18일

Community Treasure Hunt

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

Start Hunting!

Translated by