what changes are needed

accG2_A = C(:,1).*9.81;
forceG2_A = C(:,2).*0.00981;
dispG2_A = C(:,3)./1000;
time = dispG2_A./accG2_A;
s = smooth(forceG2_A);
%converted_values = findpeaks(converted_values);
%Force = converted_values(:,2);
plot (s);
how can i used this following data to plot the single cycle and not the following plot.
986 120 0
981 -60 0
984 -60 0
986 -70 0
993 -70 0
997 -70 0
1000 -70 0
1005 -70 0
1005 -70 0
1000 -70 0
994 -60 0

2 Comments

I have no idea how that data relates to that plot. The data has no value above 1005 (and has duplicate values in the first column). The data has nothing that appears to be in the range 0 to 16-ish. Your third column is all 0, so your time works out all 0.
if you see the code i am just ploting the second column, and it is the only thing i want to plot. and the x axis is time. which is not needed to be specified. i am trying to think of login to compress the data so that i get only one curve

Sign in to comment.

Answers (2)

Try this —
F = openfig('Manav Divekar untitled.fig');
F.Visible = 'off'; % Don't Show Original
Ax = F.CurrentAxes;
x = Ax.Children.XData; % Get 'X'
y = Ax.Children.YData; % Get 'Y'
[Valleys,vlocs] = findpeaks(-y, 'MinPeakProminence',5); % Locate 'Valleys'
vlocs = [1 vlocs]; % Row Vector
Ts = mean(diff(x)); % Sampling Interval
for k = 1:numel(vlocs)-1
pkrng = vlocs(k) : vlocs(k+1); % Peak Rnage (Indices)
xr{k} = x(pkrng); % 'X' Values For Peak
yr{k} = y(pkrng); % 'Y' Values For Peak
end
np = numel(xr); % Number Of Peaks
nrows = 2; % Number Of Rows For Plot
figure
for k = 1:numel(xr)
subplot(nrows,fix(np/nrows),k)
plot(xr{k}, yr{k})
grid
title(sprintf('Peak #%d',k))
end
np = numel(xr);
maxx = max(cellfun(@numel,xr)); % Maximum Segment Length
ensemble = zeros(np,maxx); % Preallocate
for k = 1:np
ensemble(k,1:numel(yr{k})) = yr{k}; % Accumulate 'Y' Values For Each Peak
end
ensmean = mean(ensemble); % Calculate Ensemble Mean
ensstd = std(ensemble); % Ensemble Standard Deviation
enssem = ensstd/sqrt(np); % Ensemble Standard Error
tval = tinv([0.025 0.975],np-1); % t-Statistic For Confidence Intervals
figure
plot((1:maxx)*Ts, ensmean)
hold on
plot((1:maxx)*Ts, ensmean+tval(:)*enssem, ':k')
hold off
grid
xlabel('x')
ylabel('y')
title('Ensemble')
legend('Mean', '± 95% CI', 'Location','best')
Esperiment to get different results.
.

4 Comments

Manav Divekar
Manav Divekar on 17 Oct 2021
Edited: Manav Divekar on 17 Oct 2021
in stead of figure if i put F= plot(), will this work?
or F.CurrentAxes won't work? Do i have use something else?
Please provide the MATLAB release you are using. My code runs without error in R2021b, and likely other recent versions/releases.
If you already have the data, so that you do not need to get it from the .fig file, just use that. I extracted the ‘x’ and ‘y’ data and saved it to a text file that I am attaching here. That eliminates the problem of having to get it from the .fig file. Ues the readtable function (or textscan) to read it.
.
I did not see that you replaced the .fig file (originally) with a .txt file. (I have no idea when that occured.) The text file would have been easier for me to work with.
Nevertheless, I provided the requested information, including plots of the original peaks (choose which of them to plot if you only want to plot one) and an ensemble average of all of them, with relevant statisitics.
If my Answer helped you solve your problem, please Accept it!
.

Sign in to comment.

filename = 'https://www.mathworks.com/matlabcentral/answers/uploaded_files/769961/G2_A.txt';
C = readmatrix(filename);
forceG2_A = C(:,2).*0.00981;
s = smooth(forceG2_A);
plot(s)
[~, idx] = findpeaks(s, 'MinPeakHeight', 6);
mid = floor(idx(1:end-1) + diff(idx)/2);
t1 = 1:mid(1);
s1 = s(t1);
t2 = mid(1)+1:mid(2);
s2 = s(t2);
plot(t1, s1, 'k*-', t2, s2, 'b+-')

Categories

Products

Tags

Asked:

on 17 Oct 2021

Commented:

on 17 Oct 2021

Community Treasure Hunt

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

Start Hunting!