Reading data from griddata - issue with type of variable.
显示 更早的评论
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 个评论
Andreas Goser
2011-3-10
Well it looks like the index is not an integer. When you have a=[1 2], then you can't expect a value for a(1.2), can't you? To solve the root cause of the problem, please psot more details.
John D'Errico
2011-3-10
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.
回答(1 个)
Andreas Goser
2011-3-10
0 个投票
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 个评论
Walter Roberson
2011-3-10
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
类别
在 帮助中心 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!