How can I index non-integer values

the code is as under: (all others are constants) I need to generate a matrix of PR of 1000 different values of R.
----------------------------------------------
PR=(1:1001);
for R=990:0.02:1010
PR(R-989)=(pt*(g^2)*sigma*(lambda^2))/(((4*pi)^3)*R^4);
end
ERROR:
Attempted to access PR(1.02); index must be a positive integer or logical.

Respuestas (2)

Bjorn Gustavsson
Bjorn Gustavsson el 8 de Feb. de 2012
Since PR is an array it has n values at indices from 1 to n. If you want to get values at other "indices" you can turn to interpolation:
nr_you_want_out = 1001;
PRinterp = interp1(1:n,PR,linspace(1,n,nr_you_want_out));
HTH
Walter Roberson
Walter Roberson el 8 de Feb. de 2012
PR=(1:1001);
Rv=990:0.02:1010;
for Ridx = 1 : length(Rv)
R = Rv(Ridx);
PR(Ridx)=(pt*(g^2)*sigma*(lambda^2))/(((4*pi)^3)*R^4);
end
Alternate solution with no loop:
R = 990:0.02:1010;
PR = pt .* (g.^2) .* sigma .* (lambda.^2) ./ (4*pi).^3 ./ (R.^4);

Categorías

Etiquetas

Preguntada:

el 8 de Feb. de 2012

Community Treasure Hunt

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

Start Hunting!

Translated by