Reading data from griddata - issue with type of variable.
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
When I tried to read data from a griddata, I got following error." Attempted to access SourcePV1(0.5,0.5); index must be a positive integer or logical"; please let me know what should I do now?
4 comentarios
John D'Errico
el 10 de Mzo. de 2011
No. Zi is defined here, not Z1. If that is your script, perhaps you might tell us what is Z1? For that matter, what is sPV1? How about PV1, also undefined, while you have given us PVi. Check your data. Consider there is a difference between i and 1. I am sure MATLAB knows the difference.
Respuestas (1)
Andreas Goser
el 10 de Mzo. de 2011
The reason why you receive this error is that you try to access SourcePV1(0.6,0.6) where SourcePV1 is a matrix. There is no concept in MATLAB of non-integer indexes of matrices and also not <1.
What you probably want can be achieved by interpolating between the values SourcePV1(1,1), SourcePV1(1,2), SourcePV1(2,1) and SourcePV1(2,2).
2 comentarios
Walter Roberson
el 10 de Mzo. de 2011
You should probably use interp2() with 'nearest' option.
Your Zi and PVi vectors do not contain the values that you think they do. For example, try
sprintf('%.90g\n', Zi(1))
Notice that it is not _exactly_ 0.01. The next element will not be _exactly_ 0.02 and so on. When you construct a vector using an increment such as 0.01 then eventually you will get an element that _looks_ like what you think it should be, but which does not have exactly the same internal value as converting the decimal value would. For example,
>> Zi(7) - 0.07
ans =
-1.38777878078145e-17
Because of this, if you did attempt to find 0.07 in your vector, you would not find it, interp2() should, though, be able to easily determine the nearest point to 0.07 .
Please read http://matlab.wikia.com/index.php?title=FAQ#Why_is_0.3_-_0.2_-_0.1_.28or_similar.29_not_equal_to_zero.3F
Ver también
Categorías
Más información sobre Matrix Indexing 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!