deltao, fo and deltafo are matrices, and i want to calculate part1Fio with changes of f(f=1:0.5:100). I try on this way, but doesnt work. Where I'm wrong?
part1Fio(length(f))=0;
for i = 1:length(f)
part1Fio(i)=(deltafo-deltao.*(fo-f(i)))./((fo-f(i)).^2+deltafo.^2);
end
It display this error "In an assignment A(I) = B, the number of elements in B and I must be the same."

Réponses (1)

Andrei Bobrov
Andrei Bobrov le 6 Nov 2013
Modifié(e) : Andrei Bobrov le 6 Nov 2013

0 votes

part1Fio = zeros([size(fo),numel(f)]);
for ii = 1:length(f)
part1Fio(:,:,ii)=(deltafo-deltao.*(fo-f(ii)))./((fo-f(ii)).^2+deltafo.^2);
end
or
s = size(fo);
[ii,jj,kk] = ndgrid(1:s(1),1:s(2),f);
ij = sub2ind(s,ii,jj);
p1 = fo(ij)-kk;
part1Fio = (deltafo(ij)-deltao(ij).*p1)./(p1.^2 + deltafo(ij).^2);

Catégories

En savoir plus sur Loops and Conditional Statements dans Centre d'aide et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by