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 commentaire

Dishant Arora
Dishant Arora le 6 Mar 2014
You might have to go for interpolation to get the value at non- integral coordinates.

Connectez-vous pour commenter.

 Réponse acceptée

Iain
Iain le 6 Mar 2014

0 votes

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 commentaires

ankita
ankita le 6 Mar 2014
but 14.6484 isn't the only value. I have an array of such values in aa1. i want the v for all these values.
You haven't told us everything we need. Let me use an analogy that tells you the method:
time = [0 0.1 0.2 0.3 0.4 .... ]; % or frequency, or number of bananas eaten, or "x"
voltage = [1 2 3 4.5 .... ]; % or current, or power, or apes fed, or "y".
Now, if you want to know y, when x = 0.05, then you need to "interpolate" or fill in the blanks.
interp1 is a simple method for automatically calculating the in-between parts, which needs to know, "x", "y" and the "x" you want to know y for.
If, instead, you have a list of times, which have known voltage, you can do something like:
times_i_want = [0 0.2 0.4 ... ];
for i = 1:numel(times_i_want)
voltage_at_time_i_want(i) = voltage(times_i_want(i) == time);
end
or...
voltage_at_time_i_want(i) = voltage(find(times_i_want(i) == time));
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 le 7 Mar 2014
Modifié(e) : Chandrasekhar le 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.

Connectez-vous pour commenter.

Plus de réponses (2)

Chandrasekhar
Chandrasekhar le 6 Mar 2014

0 votes

k = find(newf == 14.6484);
ppks = Signal_fft_hilbert(k);

17 commentaires

ankita
ankita le 6 Mar 2014
aa1 has a set of values. I want to find the Signal_fft_hilbert of all those values.
Chandrasekhar
Chandrasekhar le 6 Mar 2014
ok, but the index should be a scalar value. is there any relation between newf and Signal_fft_hilber?
ankita
ankita le 6 Mar 2014
newf is the frequency and Signal_fft_hilbert gives the amplitude. I want to find the amplitude of these particular frequencies.
Chandrasekhar
Chandrasekhar le 6 Mar 2014
does frequency at index1 of newf correspond to amplitude at index 1 of signal_fft_hilbert?
I tried this.
k= find(newf==14.6484)
abs(Signal_fft_hilbert(k))
Output was
k =
Empty matrix: 1-by-0
ans =
Empty matrix: 1-by-0
Chandrasekhar
Chandrasekhar le 6 Mar 2014
k= find(newf==14.6484) this statement should give k = ,because the first element of newf is 14.6484
ankita
ankita le 6 Mar 2014
ya but it is giving me empty matrix 1-by-0
Chandrasekhar
Chandrasekhar le 6 Mar 2014
Please find the data attached that i am using
ankita
ankita le 6 Mar 2014
Ah. I am not able to open this file
Chandrasekhar
Chandrasekhar le 6 Mar 2014
copy the file and load it into your matlab workspace. load('Data.mat'); have you done the same?
ankita
ankita le 6 Mar 2014
ya i loaded your file and got index as 1. but it shows empty matrix in my program.
Chandrasekhar
Chandrasekhar le 6 Mar 2014
Ok, you can use this data now. It is the same data that you had posted. what is the next step you have to do once you get the K value?
ankita
ankita le 6 Mar 2014
I have to find the corresponding Signal_fft_hilbert values for the corresponding frequencies. But why is the output coming for your data and not mine?
Chandrasekhar
Chandrasekhar le 6 Mar 2014
can you save your data as .mat file and attach it. I will check it. Also let me know do you have data for Signal_fft_hilbert or it is only a graph that you have.
ankita
ankita le 6 Mar 2014
anki.m is my code and hilbertData.m is the Signal_fft_hilbert values
Chandrasekhar
Chandrasekhar le 6 Mar 2014
the code(anki.m) doesnt execute. it is giving errors.
ankita
ankita le 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.

Connectez-vous pour commenter.

Niklas Nylén
Niklas Nylén le 6 Mar 2014
Modifié(e) : Niklas Nylén le 6 Mar 2014

0 votes

I misunderstood the question, removed my response but kept the answer to not lose the comments below.

3 commentaires

ankita
ankita le 6 Mar 2014
I tried this already.Gives an error: ??? Subscript indices must either be real positive integers or logicals.
Chandrasekhar
Chandrasekhar le 6 Mar 2014
can you share the data of aa1 and Signal_fft_hilbert
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

Connectez-vous pour commenter.

Catégories

En savoir plus sur Creating, Deleting, and Querying Graphics Objects dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by