Inner dimensions must agree problem
Show older comments
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 );
Answers (1)
James Tursa
on 18 May 2015
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.
Categories
Find more on Linear Algebra in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!