Error with plot command
2 ビュー (過去 30 日間)
古いコメントを表示
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
採用された回答
Alan Stevens
2023 年 1 月 16 日
編集済み: Alan Stevens
2023 年 1 月 16 日
- You haven't specified function atten_func_dist, so we can't run your code to test it.
- You specify fre as a constant, then use it again as an indexing variable - not good! Use a different indexing variable.
- You loglog plot command should probably have just loglog(1:10, atten_coeff)
その他の回答 (1 件)
Constantino Carlos Reyes-Aldasoro
2023 年 1 月 16 日
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)
0 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!