Plot data from txt file

조회 수: 26 (최근 30일)
Angel Lozada
Angel Lozada 2023년 6월 9일
댓글: Star Strider 2023년 6월 13일
Hello.
I plotted a set of data (860000 samples) getting the followed plots:
Plot 1: Emitted Signal from NAA Station (Phase)
Plot 2: Emitted Signal from NAA Station (Amplitude)
The data were taking as 10 samples per second (see attached file named Figure 1), i.e., in second 0 the are 10 numbers, in second 1 another 10 numbers, and so on.
However, when I analyze the plots, is possible to see that there are more than 10 data (>>10 numbers) in 0s, the same for second 1 and so on.
I will appreciated your help.
Regards.
unzip('Data 2.zip'),movefile('Data 2.txt','10_03_2012_Modificado.txt')
clear;
data = readmatrix('10_03_2012_Modificado.txt');
T = data(:,1);
T = seconds(data(:,1));
T.Format = 'hh:mm';
T2 = data(:,2);
figure;
plot (T,T2,'x');
title 'Emitted Signal from NAA Station';
ylabel ('Phase');
xlabel ('Samples');
T = data(:,1);
T = seconds(data(:,1));
T.Format = 'hh:mm';
T3 = data(:,3);
figure;
plot (T,T3,'x');
title 'Emitted Signal from NAA Station';
ylabel ('Apmlitude');
xlabel ('Samples');
  댓글 수: 2
Star Strider
Star Strider 2023년 6월 10일
I am not certain what you want to do.
The time vector appears to be consistent. The only detail that I can add is to combine the amplitude and phase data to create a complex signal and then plot the magnitude of the result —
Uzp = unzip('Data 2.zip');
A1 = readmatrix(Uzp{1})
A1 = 864000×3
0 -101.0300 23.5600 0.1000 -100.2100 23.8600 0.2000 -101.7000 23.5600 0.3000 -107.6600 23.4700 0.4000 -110.5400 22.7800 0.5000 -112.2900 21.6600 0.6000 -107.4600 21.6700 0.7000 -115.9300 21.2700 0.8000 -114.0500 22.2300 0.9000 -110.9900 22.2400
t = seconds(A1(:,1));
figure
yyaxis left
plot(t, A1(:,2))
ylabel('Phase (°)')
grid
yyaxis right
plot(t, A1(:,3))
ylabel('Amplitude')
xlabel('Time')
xlim([t(1) t(end)])
cs = A1(:,3) .* exp(1j*deg2rad(A1(:,2))); % Complex Signal
figure
plot(t, abs(cs))
grid
xlabel('Time')
ylabel('Magnitude')
xlim([t(1) t(end)])
I do not know what the result is supposed to look like, or what the data actaully represent.
.
Angel Lozada
Angel Lozada 2023년 6월 10일
Dear Star Strider.
First at all, thanks for your soon reply and support.
I will try to explain in a better way my inquiry.
As you can see in previous attached .txt file there are 3 columns indicating a giving information for a signal.
Column 1: seconds and sample in each second; Column: 2 Phase and Column 3: Amplitude.
Let say we take a look to Phase data. In column 1 the collected data begin at 0s and during this time we have 10 samples (from 0.0 to 0.9), then at 1s we have other ten samples (1.0 to 1.9), and so on.
Attached file Figure 3 shows the expected plot (plotting 10 samples in each second) and also shows what I am getting in current Phase plot (a lot of samples between second 0 and 1). You can see in this Figure 3 that is a kind of discrete plot, because there is information (samples) only in each second and not in between.
Again, thanks for your support and patience.
Regards.

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

채택된 답변

Star Strider
Star Strider 2023년 6월 10일
If you simply want to aggregate the data in each second and plot them that way, try something like this —
Uzp = unzip('Data 2.zip');
A1 = readmatrix(Uzp{1})
A1 = 864000×3
0 -101.0300 23.5600 0.1000 -100.2100 23.8600 0.2000 -101.7000 23.5600 0.3000 -107.6600 23.4700 0.4000 -110.5400 22.7800 0.5000 -112.2900 21.6600 0.6000 -107.4600 21.6700 0.7000 -115.9300 21.2700 0.8000 -114.0500 22.2300 0.9000 -110.9900 22.2400
t = seconds(A1(:,1));
ixv = ceil(A1(:,1) + 1E-12); % Index Vector For 'accumarray'
secv = accumarray(ixv, (1:size(A1,1)).', [], @(x){A1(x,[2 3])}) % Aggregatte Points By Second
secv = 86400×1 cell array
{10×2 double} {10×2 double} {10×2 double} {10×2 double} {10×2 double} {10×2 double} {10×2 double} {10×2 double} {10×2 double} {10×2 double} {10×2 double} {10×2 double} {10×2 double} {10×2 double} {10×2 double} {10×2 double}
A2 = reshape(cell2mat(secv).', 2,10,[]); % Convert To Numeric MAtrix From Cell Array & Reshape ARray
tv = unique(ixv); % Corresponding Time Vector
figure
yyaxis left
plot(tv, squeeze(A2(1,:,tv)), '.')
ylabel('Phase (°)')
grid
yyaxis right
plot(tv, squeeze(A2(2,:,tv)), '.')
ylabel('Amplitude')
xlabel('Time')
% xlim([tv(1) tv(end)])
xlim([0 5.5])
% cs = A2(2,:,:) .* exp(1j*deg2rad(A2(1,:,:))); % Complex Signal
%
% figure
% plot(tv, squeeze(abs(cs)))
% grid
% xlabel('Time')
% ylabel('Magnitude')
% % xlim([0 5.5])
% xlim([tv(1) tv(end)])
This plots them as dots rather than asterisks. Choose whatever marker you want.
.
  댓글 수: 2
Angel Lozada
Angel Lozada 2023년 6월 13일
Star Strider.
Thanks for your cooperation.
I appreciated.
Star Strider
Star Strider 2023년 6월 13일
As always, my pleasure!

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

추가 답변 (0개)

카테고리

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

태그

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by