how can I get the following graph from this data, changes are required in the code
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Manav Divekar
am 18 Okt. 2021
Beantwortet: Star Strider
am 19 Okt. 2021
clc
clear all
close all
% Lab 2 Group G2 Data Analysis
%[files,path] = uigetfile({'.txt'},'MultiSelect', 'on');
%if iscell(files)
% for n = 1:length(files)
% data = importdata(fullfile(path,files{n})); % fullfile including path
% save data
%end
%else
% data = importdata(fullfile(path,files));
% save data
%end
%G2test = importdata('G2_A.txt','G2_C.txt');
%fid= fopen('G2_A.txt');
%C= readmatrix('data', 'NumHeaderLines',8);
C= readmatrix('G2_A.txt', 'NumHeaderLines',8);
dG2test = C(:,3);
for i = 1:length(dG2test)
if dG2test(i)<0
dG2test(i) = dG2test
end
end
%Convert to SI Units
accG2test = C(:,1).*9.81;
forceG2test = C(:,2).*0.00981;
dispG2test = C(:,3)./1000;
time = dispG2test./accG2test;
s = smooth(forceG2test);
%Find the peak and plot
[~, idx] = findpeaks(s, MinPeakHeigh = 6);
%minAdult = islocalmin(s);
%minLocs = find(minAdult ==1);
%for j = 1:11
%for k = 5:16-1
% newdata{j,:} = dataAdult(minLocs(k):minLocs(k+1),:);
% newdataAdult{minLocs(1):(minLocs(k+1)-minLocs(k)),:} = newdata;
%end
%end
mid = floor(idx(1:end-1) + diff(idx)/2);
t1 = 1:mid(1);
s1 = s(t1);
%t2 = 1:mid(6);
%s2 = s(t2);
plot(t1,s1);
hold on
Please Refer the attached .txt file for the data
0 Kommentare
Akzeptierte Antwort
Star Strider
am 19 Okt. 2021
Try something like this —
T1 = readtable('https://www.mathworks.com/matlabcentral/answers/uploaded_files/771138/G2_A.txt', 'VariableNamingRule','preserve')
%Convert to SI Units
accG2test = T1{:,1}.*9.81;
forceG2test = T1{:,2}.*0.00981;
dispG2test = T1{:,3}./1000;
% time = dispG2test./accG2test;
forceG2test2 = smoothdata(forceG2test, 'sgolay', 100);
[Vlys,vlocs] = findpeaks(-forceG2test2, 'MinPeakProminence',0.5); % Valleys Of Smoothed Data
Vlys = [-forceG2test2(1); Vlys];
vlocs = [1;vlocs];
Ts = 1; % Sampling Interval
t = 1:height(T1);
figure
plot(t, forceG2test2)
hold on
plot(t(vlocs), -Vlys, '+r')
hold off
for k = 1:numel(vlocs)-1
idx{k} = vlocs(k):vlocs(k+1); % Index Range For This Segment
tc{k} = t(idx{k}); % Time Vector
sc{k} = forceG2test(idx{k}); % Signal Segment
end
tcmax = max(cellfun(@numel,tc)); % Maximum Segment Length
ensb = zeros(tcmax,numel(idx)); % Preallocate
for k = 1:numel(idx)
ensb(1:numel(idx{k}),k) = sc{k}; % Create 'Ensemble'
end
figure
plot(1:tcmax, ensb) % Plot Ensemble
grid
xlabel('Index')
ylabel('Amplitude')
I have no idea which signal ‘Deflection’ is. This creates san ensemble based on the starting and ending points of each forceG2test’ pulse.
Experiment to get different results.
.
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Spectral Measurements finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!