Error with plot command
3 次查看(过去 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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Geographic Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!