how to solve this error
显示 更早的评论
I got this error Subscript indices must either be real positive integer or logical
I am tried to removed the range of desired signal from dataset matrix and find the power of that range. then the remaining will be interferance and also i want to find the power of remaining range
the error occured when i want to find the power of interferance
PI=mean(mean(SysSetup.Dataset(:,RI).^2))
this is my code
25 个评论
Geoff Hayes
2019-2-24
Redflower - so the code is failing at the 7th or 8th line? What can you tell us about RI? i.e. what are the values of this array? Are they positive integers or (as the error message suggests) something else?
Walter Roberson
2019-2-24
When you use linspace() you should assume that you are going to get back values that are not necesarily positive integers. If you need positive integers, it is safer to use the colon operator, probably in conjunction with floor() or ceil().
Perhaps in your case it would be sufficient to index at round(RI) instead of at RI .
Redflower
2019-2-25
Walter Roberson
2019-2-25
You attach code but not sysSetup or the other variables needed for us to run the code to test.
Redflower
2019-2-25
Walter Roberson
2019-2-25
function ModIdentdataset not defined.
Redflower
2019-2-25
Walter Roberson
2019-2-25
It looks like it is necessary to call
ModDatasetGenpaper; %to define SysSetup
Train_cumulantpaper; %to define net
something unknown at this point %to define ModIdentdataset
AccuVsSIR2cum; %to do computation
Unfortunately without the code to define ModIdentdataset it is difficult for us to test.
Redflower
2019-2-25
Walter Roberson
2019-2-25
Okay, finally I can reproduce your error.
You copy the test dataset into RI and you delete the columns given by Rd (a list of positive integers) from that. The result is a 2D numeric array of floating point data with fewer columns that the test dataset.
You then try to index sysSetup.Dataset() using that floating point dataset as indices.
I suspect you want to instead take
RI = setdiff(1:size(Dataset_test,2), Rd);
That is, I suspect you want RI to be the list of remaining indices.
Redflower
2019-2-26
Walter Roberson
2019-2-26
Ah, yes, if RI is not the same length as Rd then line 16 would trigger an error.
I cannot suggest any solution due to the lack of documentation about what Rd and RI are intended to represent.
Redflower
2019-3-3
Walter Roberson
2019-3-3
I do not know. If I had documentation about what Rd and RI should mean, then I might be able to assist.
Redflower
2019-3-4
Walter Roberson
2019-3-4
On line 16, the reference to RI should likely be a reference to Rd
Redflower
2019-3-4
Walter Roberson
2019-3-4
It is a little after 1 AM where I am. I could go back to examine your code and predict what bugs you might have introduced when you made unknown changes to your code, and then tell you how to correct each of the possibilities... or I could go to bed and check in the morning to see whether you posted your updated code.
Redflower
2019-3-4
Redflower
2019-3-5
Redflower
2019-3-5
Walter Roberson
2019-3-5
What are you expecting the linspace() to do for you at that point?
Redflower
2019-3-5
Walter Roberson
2019-3-5
What do you think the result from that linspace() shoud be?
Are you expecting a series of consecutive integers? Are you expecting a series of integers with a constant gap between them? Are you trying to "sample" a range of integers at as close as you can get to equal partitions? Are you trying to extract the index numbers of all samples belonging to a particular class when the SysSetup information knows where the class starts and how long it is?
Redflower
2019-3-5
回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
