good morning everyone can anyone answer me this question ? i have an error in the matlab code
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (3)
jeewan atwal
el 23 de Nov. de 2019
Editada: jeewan atwal
el 23 de Nov. de 2019
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
el 23 de Nov. de 2019
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
el 23 de Nov. de 2019
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. :)
Ver también
Categorías
Más información sobre Startup and Shutdown en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!