Find the max amplitude of Frequency from text file

조회 수: 1(최근 30일)
vu ngothanh
vu ngothanh 2015년 5월 13일
댓글: vu ngothanh 2015년 5월 13일
I have a text file like this
0.000000,-1.721511E-5,-2.869001E-5
3.906250E-5,-1.859251E-5,-3.247638E-5
7.812500E-5,-2.083079E-5,-2.504133E-5
0.000117,-1.996991E-5,-2.779505E-5
0.000156,-1.866138E-5,-3.044551E-5
0.000195,-2.241480E-5,-2.982592E-5
0.000234,-2.027983E-5,-2.579860E-5
0.000273,-1.786938E-5,-2.497249E-5
0.000312,-1.910904E-5,-2.741642E-5
.......
0.000352,-1.749059E-5,-2.748526E-5
0.000391,-2.141618E-5,-2.855233E-5
0.000430,-2.062418E-5,-2.751968E-5
0.000469,-1.817929E-5,-2.696894E-5
0.000508,-1.511457E-5,-3.030782E-5
0.000547,-1.931565E-5,-2.597071E-5
0.000586,-1.855808E-5,-3.158142E-5
0.000625,-2.072748E-5,-3.054877E-5
0.000664,-2.072748E-5,-3.171910E-5
0.000703,-1.917791E-5,-3.047993E-5
0.000742,-2.289689E-5,-2.486922E-5
0.000781,-2.165723E-5,-2.941286E-5
0.000820,-2.076192E-5,-3.068646E-5
0.000859,-1.776607E-5,-2.583303E-5
0.000898,-1.728398E-5,-2.748526E-5
First colum is value of time, Second and 3rd colum is value of frequency at point 1 and 2. I need to get the max and the second max value of amplitude of frequency at point 1, because maybe there are some bad value of amplitude of frequency at point 1. Then, I need to export the value of the range in the black box. How can I do it.

답변(2개)

Abhiram Bhanuprakash
Abhiram Bhanuprakash 2015년 5월 13일
Hi Vu,
In your case, since you have only text data (without character strings), I think you can save your data into a CSV file, and use 'csvread' to import the data into the MATLAB workspace. Documentation for 'csvread' is here
After you get the data into MATLAB, you can use it for further processing. For example, in your case, you can use something like:
a = csvread('data.csv'); %where data.csv file contains the data which you have pasted here
maxval = max(a(:,2)); %maximum of second column
To import data from a general text file, you can use 'textscan'. Documentation here
Hope this helps,
Cheers!
Abhiram.
  댓글 수: 5
vu ngothanh
vu ngothanh 2015년 5월 13일
http://en.wikipedia.org/wiki/Frequency cycles in my mean is T which T=1/f so hard to explain. sorry about that

댓글을 달려면 로그인하십시오.


Walter Roberson
Walter Roberson 2015년 5월 13일
fid = fopen('YourFile.txt');
C = textscan(fid, '%f,%f,%f', 'CollectOutput', 1);
close(fid);
point1 = C{1}(:,2);
[up1, upa] = unique(point1);
maxp1 = up1(end);
maxp1pos = upa(end);
max2p1 = up1(end-1);
max2p1pos = upa(end-1);
Note that you have not clearly defined "second maximum" if what you might have is a peak over several values rather than a single bad point.
  댓글 수: 1
vu ngothanh
vu ngothanh 2015년 5월 13일
Hi Walter,
My file content the FREQUENCY of one element in a short time. In my file, to show 1 cycle, it need alot of value. I think, if we remove the biggest value to get the second biggest value like that, it can be done, but, that second value like that may be in the same cycle. I need the second max value but in the different cycle. Do you mean what I say. Sorry, my english is not too good.
Thank you for your time.

댓글을 달려면 로그인하십시오.

Community Treasure Hunt

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

Start Hunting!

Translated by