Error with plot command

1 vue (au cours des 30 derniers jours)
David Harra
David Harra le 16 Jan 2023
Commenté : David Harra le 16 Jan 2023
I am just trying to do a basic plot but I can't seem to get it to work. I keep getting an error saying
"Index exceeds the number of array elements. Index must not exceed 1"
My code for the plot is below
clear all
clc
fre = 10e6; % Frequency in Hz
wave_type = 1; % wave_type Longitudinal == 1; Shear == 2
atten_type = 1; % atten_type Distribution == 1; Single Grain Size == 2; Rayleigh Approx. == 3
L = 15; % distribution mean in um
sigma_d = 0.5; % distribution width (PDF in https://en.wikipedia.org/wiki/Log-normal_distribution)
% % Titanium
C11 = 160E9; C12 = 90E9; C13 = 66E9; C33 = 181E9; C44 = 46.5E9; % Single crystal elastic constants
[c11, c12, c13, c14, c15, c16, c22, c23, c24, c25, c26, c33, c34, c35, c36, c44, c45, c46, c55, c56, c66] = deal(C11,C12,C13,0,0,0,C11,C13,0,0,0,C33,0,0,0,C44,0,0,C44,0,(1/2)*(C11-C12));
density = 4506;
velocity= 6100;
for fre = 1:10
atten_coff(1,fre) = atten_func_dist(fre,wave_type,atten_type,L,sigma_d,density,c11, c12, c13, c14, c15, c16, c22, c23, c24, c25, c26, c33, c34, c35, c36, c44, c45, c46, c55, c56, c66);
end
loglog(fre(1:10), atten_coff)
Thanks
Dave
  1 commentaire
Kevin Holly
Kevin Holly le 16 Jan 2023
What is atten_func_dist?

Connectez-vous pour commenter.

Réponse acceptée

Alan Stevens
Alan Stevens le 16 Jan 2023
Modifié(e) : Alan Stevens le 16 Jan 2023
  1. You haven't specified function atten_func_dist, so we can't run your code to test it.
  2. You specify fre as a constant, then use it again as an indexing variable - not good! Use a different indexing variable.
  3. You loglog plot command should probably have just loglog(1:10, atten_coeff)
  1 commentaire
David Harra
David Harra le 16 Jan 2023
Thank You.
That makes sense now :)

Connectez-vous pour commenter.

Plus de réponses (1)

Constantino Carlos Reyes-Aldasoro
I do not think this is a problem of plot, but rather that your variable has only 1 value and you are addressing a higher value. E.g.
V=[ 1 2 3];
V(4)
Index exceeds the number of array elements. Index must not exceed 3.

Tags

Produits


Version

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by