index error for find function

3 views (last 30 days)
ankita
ankita on 6 Mar 2014
Edited: Chandrasekhar on 7 Mar 2014
I am trying to find the value of Signal_fft_hilbert at the values of newf. But i get the error:
??? Attempted to access Signal_fft_hilbert(14.6484); index must be a positive integer or logical.
I want to find the value at exactly 14.6484. How can I find the value?
newf=aa1(:)'
for s=1:length(newf)
ppks=find(Signal_fft_hilbert(newf(s)))
end
  1 Comment
Dishant Arora
Dishant Arora on 6 Mar 2014
You might have to go for interpolation to get the value at non- integral coordinates.

Sign in to comment.

Accepted Answer

Iain
Iain on 6 Mar 2014
Ok, it looks like you've got a vector "Signal_fft_hilbert", which I'm going to call "v".
If want v(14.6484). The only way you can get v(14. ... ) is if you interpolate.
doc interp1 % will tell you all about one function for interpolation.
Alternatively, if you want the v that corresponds to something having a value you could do something like:
v( time == 14.684324)
or
v(find(time > 14.00))
  4 Comments
ankita
ankita on 7 Mar 2014
Thanks alot Lain. I had 1 more doubt. This is my code
for k=1:length(peaks)
top1{k}=freq_s(locs(k))
for s1=1:length(peaks)
xx{s1}=top1{k}*s1;
end
[xx1]=[xx(:)]';
xx2=cell2mat(xx1);
aa1(k,:)=xx2;
In the above answers you can see my output aa1. Is there a method where I can get output like for each top1 with their subscripts included like top11 for i=1,top12 for i=2..... see my basic idea is to create different arrays of top1,which is a frequency, and show the values of corresponding Signal_fft_hilbert. The user can then pick which top1 values suit them and they will get the final Signal_fft_hilbert values. Any suggestions?
Chandrasekhar
Chandrasekhar on 7 Mar 2014
Edited: Chandrasekhar on 7 Mar 2014
hope this works replace
top1{k}=freq_s(locs(k)) with
evalin('base',['top1' num2str(k) '=freq_s(locs(k))';])
this will append the 'k' value to top1 every time and creates a new variable top1k in the workspace.

Sign in to comment.

More Answers (2)

Chandrasekhar
Chandrasekhar on 6 Mar 2014
k = find(newf == 14.6484);
ppks = Signal_fft_hilbert(k);
  17 Comments
Chandrasekhar
Chandrasekhar on 6 Mar 2014
the code(anki.m) doesnt execute. it is giving errors.
ankita
ankita on 6 Mar 2014
maybe because of the file in the first 2-3 lines. you can check the code from line 136. there the Signal_fft_hilbert is calculated.

Sign in to comment.


Niklas Nylén
Niklas Nylén on 6 Mar 2014
Edited: Niklas Nylén on 6 Mar 2014
I misunderstood the question, removed my response but kept the answer to not lose the comments below.
  3 Comments
Chandrasekhar
Chandrasekhar on 6 Mar 2014
can you share the data of aa1 and Signal_fft_hilbert
ankita
ankita on 6 Mar 2014
aa1 =
14.6484 29.2969 43.9453 58.5938 73.2422 87.8906 102.5391
51.2695 102.5391 153.8086 205.0781 256.3477 307.6172 358.8867
65.9180 131.8359 197.7539 263.6719 329.5898 395.5078 461.4258
80.5664 161.1328 241.6992 322.2656 402.8320 483.3984 563.9648
95.2148 190.4297 285.6445 380.8594 476.0742 571.2891 666.5039
109.8633 219.7266 329.5898 439.4531 549.3164 659.1797 769.0430
124.5117 249.0234 373.5352 498.0469 622.5586 747.0703 871.5820
newf =
Columns 1 through 7
14.6484 51.2695 65.9180 80.5664 95.2148 109.8633 124.5117
Columns 8 through 14
29.2969 102.5391 131.8359 161.1328 190.4297 219.7266 249.0234
Columns 15 through 21
43.9453 153.8086 197.7539 241.6992 285.6445 329.5898 373.5352
Columns 22 through 28
58.5938 205.0781 263.6719 322.2656 380.8594 439.4531 498.0469
Columns 29 through 35
73.2422 256.3477 329.5898 402.8320 476.0742 549.3164 622.5586
Columns 36 through 42
87.8906 307.6172 395.5078 483.3984 571.2891 659.1797 747.0703
Columns 43 through 49
102.5391 358.8867 461.4258 563.9648 666.5039 769.0430 871.5820
this is the plot of Signal_fft_hilbert

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!