Info

This question is closed. Reopen it to edit or answer.

??? Attempted to access V(4.15712e+008); index must be a positive integer or logical. Error in ==> modallllll at 50 an = (w * p0*c0^2)/V(2 * damping *wn*w +1*(w^2 -wn^2)) * p_xyz_t;

1 view (last 30 days)
Hi, I am having a logical error with V and had a go at fixing it using the logical function and unfortunately had no luck.
This is my code
close all;
clear all;
ampl = 1;
l_x = 5; % meters
l_y = 6; % meters
l_z = 4;
step = 0.0125; % meters
n_x = 4; % modal index
n_y = 3; % modal index
x_vector = 0: step: l_x;
y_vector = 0: step: l_y;
length_y = length (y_vector);
length_x = length (x_vector);
p_xyz_t = zeros (length_x,length_y);
c = 341; %m/s
X= (n_x)/(l_x);
Y =(n_y)/(l_y);
f_acoust = (c/2)*sqrt(X^2+Y^2);
period = 1 / f_acoust;
nbr_of_frames = 90;
f_sampling = 20* f_acoust; % Hz
delta_t = 1 / f_sampling; % seconds
for idx_t = 1 : nbr_of_frames
for idx_x = 1: length_x
p_xyz_t (idx_x, :) = ampl * cos(2*pi*idx_t*delta_t/period)*...
cos(n_x*pi*(idx_x-1)*step/l_x) * cos((n_y*pi*y_vector/l_y));
end
end
%%%for single point monopole source at rq
w = 2 * pi * f_sampling;
p0 = 1.204;
c0 = 341;
V = 60;
damping = 0.2;
wn = f_acoust * 2 * pi;
p_xyz_t = logical(p_xyz_t);
V = logical(V);
an = (w * p0*c0^2)/V(2 * damping * wn * w +1*(w^2 -wn^2)) * p_xyz_t;
figure(1) contour( p_xyz_t); axis ([1, length_y, 1, length_x, -1.5*ampl, 1.5*ampl ]);
figure(2) surf( p_xyz_t); axis ([1, length_y, 1, length_x, -1.5*ampl, 1.5*ampl ]);

Answers (2)

Andreas Goser
Andreas Goser on 23 May 2014
Edited: Andreas Goser on 23 May 2014
It is in this expression:
V(2 * damping * wn * w +1*(w^2 -wn^2))
V is a scalar (1x1 matrix) in your code and cannot be indexed.
You propbably want to do something completely different.

Azzi Abdelmalek
Azzi Abdelmalek on 23 May 2014
Use
V(int64(2 * damping * wn * w +1*(w^2 -wn^2)))
  1 Comment
Clarissa
Clarissa on 23 May 2014
When I used that it came up with a new error
??? Index exceeds matrix dimensions.
Error in ==> modallllll at 50 an = (w * p0*c0^2)/V(int64(2 * damping wn * w +1(w^2 -wn^2))) * p_xyz_t;

Community Treasure Hunt

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

Start Hunting!