1 view (last 30 days)

Show older comments

Hei All,

I have been getting the error message "Subscript indices must either be real positive integers or logicals. " referring to the calculation of z(i, j) whilst working on the code below. I have spent hours trying to fix the issue, but couldn't figure out what I was missing.

a = 0.2302;

N=4;

theta = linspace(0, 2 * pi * pi, N);

r = linspace(a, 2 * a, N);

sigma_TT = r.^4 .* cos(2 .* theta);

x = zeros(N, N);

y = zeros(N, N);

z = zeros(N, N);

for i = 1:N

for j = 1:N

x(i, j) = (cos(theta(i)))' * r(j);

y(i, j) = (sin(theta(i)))' * r(j);

z(i, j) = real(sigma_TT([theta(i), r(j)]));

end

end

The for loop part is actually what I trying to convert from python to MATLAB. In python it is expressed as:

x = r * np.cos(theta[:,None])

y = r * np.sin(theta[:,None])

z = sigma_TT(SHmax, Shmin, Pp, Pm, a, r, theta[:,None])

Any help on this issue would be much appreciated.

Image Analyst
on 16 Aug 2016

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

Start Hunting!