How I can Plot Data Samples as Data values in Y-axis and Sample counter converted to micro second values in X-axis? Then get average and standard variation values?
8 次查看(过去 30 天)
显示 更早的评论
I imported the excel file which have Two coloumns and 100,001 rows.
1- I use the plot icon in MATLAB to plot all of the rows in the first column. for example below:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1137755/image.jpeg)
2- Then, I get the below graph:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1137760/image.jpeg)
2- How I can do this plot again, but insetad of the Sample counter values in x-axis, I want to make it (time).
For example, convert the first sample = 1 TO BE first sample = 1e-06 (micro seconds) and to all of the other samples till I reach 100,001 e-06. I can explain it again below:
- The distance between samples is 1us (microsecond).
- We take the samples, create time axis. And, We’ve got 100,001 point.
- So we got time samples, or sample counter (SC), and we translate this into time, Which will be 100,001 * 1 us (micro seconds) which will be 100,000 us (microseconds)
3- After I finish from above steps, I will have my samples in the y-axis and I will have the time in micoseconds in x-axis.
4- Then I want to plot The pulse,which is in 50 us, that’s the ON time (included in the plot). And, the OFF time is 950 us (not in plot). However:
- The start of analysis of 1st window, is 15us + 5 um. That’s our start.
- The end of first-time window is 15us + 5us + 40us. Thats our end. Then we can plot it.
5- So after we finish from the first pulse above which is considers as number 0. Then we have to do it to the rest for pulses which will be for example from 1 to 99. And we use a counter, for example,"m" to be used for 1 to 99 in below equation:
- 15us + 5us + 40us + m*1000us.
- Therefore I need to repeat for example, using "for" loop.
- and then we just hold on for the 40us AND hold off for the rest in each loop. Then plot all of those windows and then we should have a line.
6- Also when we do the “for” loop, for each time window , I want to calculate average as well AND standard deviation. I also want to plot thses and see if there a trend
0 个评论
回答(1 个)
Cris LaPierre
2022-9-27
2. Select your x values, then use Ctrl+click to select your y values (should have 2 columns selected. Not go to the plots tab and select the plot you want. See this video. this approach will not work if you plan to loop your code, however. You must write the actual code.
4. The easiest way to plot is to create a vector of your pulse values, and a corresponding vector of time values. Then plot them using the appropriate plotting function. To add 2 lines to the same plot, use hold on followed by hold off when done.
15 个评论
Cris LaPierre
2022-9-30
编辑:Cris LaPierre
2022-9-30
Here, I think it is easier to work in indices rather than time. Again, you have the equation for the indices you want already, so now just incorporate it into your code. I'm not sure what exactly you want your final plot to be, so I took a guess by plotting the mean of mag and phase over each 40
pulse.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1141420/image.png)
% Start is the same as before
file = "https://www.mathworks.com/matlabcentral/answers/uploaded_files/1140105/MATLAB%20DATA%20-%20Exp%207.xlsx";
M = readtable(file)
A = M.I_inc;
B = M.Q_inc;
E2 = complex(A,B);
C = M.I_ref;
D = M.Q_ref;
F2 = complex(C,D);
% getting IMABS
Inc_mag = abs(E2);
Ref_mag = abs(F2);
Inc_phase_deg = angle(E2) * 180/pi;
Ref_phase_deg = angle(F2) * 180/pi;
%==
s11 = F2./E2;
s11_mag = abs(s11);
s11_phase_deg = angle(s11) * 180/pi;
%==
t = (1:length(s11_mag))*1e-6;
plot(t,s11_mag)
ylabel('Magnitude')
xlabel('Time (s)')
% define pulse characteristics
start = 20;
width = 40;
gap = 1000;
% capture results in a new table, pStats
pStats = table('Size',[100 3],'VariableTypes',{'double','double','double'},'VariableNames',["Time","Avg_mag","Avg_phase"]);
ind = start:gap:length(s11_mag);
for p = 1:length(ind)
magdata = s11_mag(ind(p):(ind(p)+width));
phasedata = s11_phase_deg(ind(p):(ind(p)+width));
pStats.Time(p) = t(ind(p));
pStats.Avg_mag(p) = mean(magdata);
pStats.Avg_phase(p) = mean(phasedata);
end
% view results
pStats
figure
yyaxis left
plot(pStats,"Time","Avg_mag")
ylabel('Magnitude')
xlabel('Time (s)')
yyaxis right
plot(pStats,"Time","Avg_phase")
ylabel('Phase (deg)')
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!