good morning everyone can anyone answer me this question ? i have an error in the matlab code
1 回表示 (過去 30 日間)
古いコメントを表示
here are some of the programs that I'm working on
sou_y = [5 10];
rec_y = [5 25 40];
t_obs = [0.1000 0.0977 0.0908];
pan_ray_tot = [ 100.0000 101.9084 105.9481
100.1249 101.1187 104.4031];
vsem = zeros (length(sou_y), length(rec_y) );
for i = 1 :length(sou_y)
for j = 1 :length(rec_y)
vsem(i,j) = pan_ray_total (i,j) ./ t_obs (i,j);
end
end
and i have problem like this
Attempted to access t_obs(2,1); index out of bounds because size(t_obs)=[1,3].
how can i fix this?
0 件のコメント
回答 (3 件)
jeewan atwal
2019 年 11 月 23 日
編集済み: jeewan atwal
2019 年 11 月 23 日
t_obs = [0.1000 0.0977 0.0908];
This vector t_obs has only one row and three column.
when you are executing your for loop, it is trying to access value in 2nd row of t_obs. Since t_obs does not have 2nd row, thats why matlab is unable to find value t_obs(2,1).
Hope this helps in correcting your t_obs vector.
KALYAN ACHARJYA
2019 年 11 月 23 日
To avoid the error, you must define the t_obs size as 2x3
format shortG
sou_y = [5 10];
rec_y = [5 25 40];
t_obs = [0.1000 0.0977 0.0908
0.1000 0.0977 0.0908]; % Here I have modified see, added the 2nd row example
pan_ray_tot = [100.0000 101.9084 105.9481
100.1249 101.1187 104.4031];
vsem=zeros(length(sou_y),length(rec_y));
for i=1:length(sou_y)
for j=1:length(rec_y)
vsem(i,j)=pan_ray_tot(i,j)/t_obs(i,j);
end
end
vsem
If the asumption is OK, then you can avoid loop here (Recomended)
format shortG
sou_y = [5 10];
rec_y = [5 25 40];
t_obs = [0.1000 0.0977 0.0908
0.1000 0.0977 0.0908];
pan_ray_tot = [100.0000 101.9084 105.9481
100.1249 101.1187 104.4031];
vsem=pan_ray_tot./t_obs
Darshan Sen
2019 年 11 月 23 日
Hello No Freed.
First error: line 10: pan_ray_total should be pan_ray_tot instead as that's the name you used at line 5.
Second error:
>> size(t_obs)
ans =
1 3
But since i , t_obs must have atleast 2 rows. Since t_obs has only 1 row and in the loop, you are trying to access elements of the row indexed by i = 2, you are getting an error.
The solution is to make t_obs have atleast as many rows as length(sou_y) and as many columns as length(rec_y).
Hope this was helpful. :)
参考
カテゴリ
Help Center および File Exchange で Startup and Shutdown についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!