Getting directly range of value from MATLAB table?

조회 수: 5 (최근 30일)
George Ghimire
George Ghimire 2020년 10월 8일
댓글: Star Strider 2020년 10월 8일
Hi Everyone
Consider I have a MATLAB table which contains a frequency value from 1 Hz to 1000 Khz. From here I want to take only data between 300 Khz to 400 Khz. I donot want to use indexing . Is there anything i can do to extract directly the values ranging from 300 Khz to 400 Khz.
My f should have value like this in script (without indexing)
f = 300 Khz to 400 Khz
Thanks

채택된 답변

Star Strider
Star Strider 2020년 10월 8일
Try this:
Freq = 1:10:1E+6; % Create Frequencies
Amplitude = randn(size(Freq(:))) +1j*randn(size(Freq(:))); % Create Amplitude (Or Whatever The Rest Of The Table Contains)
T1 = table(Freq(:),Amplitude); % Create Table
A1 = table2array(T1); % Extract Data Array (Eaiser To Work With Here)
FreqRange = (300:400)*1E+3; % Define As 300kHz - 400kHz
F300_400 = interp1(A1(:,1),A1(:,2), FreqRange).'; % Use Interpolation To Extract Desired Data —> No Indexing!
T2 = table(FreqRange(:), F300_400); % New Table (If Desired)
.
  댓글 수: 2
George Ghimire
George Ghimire 2020년 10월 8일
Hi Star Its quite good example you gave. But you have taken frequency as an input and exported the data which are in 300-400 Khz. But in my case frequency is one of my output which is inside the table and i want directly taking its range if possible
Star Strider
Star Strider 2020년 10월 8일
Thank you!
I realise that you want frequency as an output.
In my code, the result ‘T2’ uses frequency (as ‘FreqRange’) as the first column, and the other values, as ‘F300_4100’ as the second (or more) columns.
All the information for that frequency range is in ‘T2’, including the frequencies.

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

추가 답변 (1개)

Jon
Jon 2020년 10월 8일
편집: Jon 2020년 10월 8일
I'm not sure what you mean by not using indexing. In case this helps here is one way to do it. Suppose you have a table T, with columns f (in Hz) and x for the frequency and corresponding data values resp
f = T.f(T.f >= 300e3 & T.f <= 400e3)
x = T.x(T.f >= 300e3 & T.f <= 400e3)
or somewhat more efficiently:
idl = T.f >= 300e3 & T.f <= 400e3
f = T.f(idl)
x = T.x(idl)
  댓글 수: 2
Jon
Jon 2020년 10월 8일
편집: Jon 2020년 10월 8일
Obviously my answer uses indexing, which perhaps is counter to what you asked. I'm just wondering why you would not want to use indexing. What, if anything, would be the problem for you in doing it as I suggest. It seems quite simple, but maybe I am missing something.
George Ghimire
George Ghimire 2020년 10월 8일
I am not preferring indexing because my table has many sub division and sub sub division inside, At the end i have around 5200 frequency data and i need to extract them in different range for different calculation. Thats why i want direct taking of frequency values

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

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by