Error with plot command

조회 수: 1 (최근 30일)
David Harra
David Harra 2023년 1월 16일
댓글: David Harra 2023년 1월 16일
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
Kevin Holly
Kevin Holly 2023년 1월 16일
What is atten_func_dist?

댓글을 달려면 로그인하십시오.

채택된 답변

Alan Stevens
Alan Stevens 2023년 1월 16일
편집: Alan Stevens 2023년 1월 16일
  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
David Harra
David Harra 2023년 1월 16일
Thank You.
That makes sense now :)

댓글을 달려면 로그인하십시오.

추가 답변 (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.

카테고리

Help CenterFile Exchange에서 Design of Experiments (DOE)에 대해 자세히 알아보기

태그

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by